npm install --save nodemailer
var nodemailer = require('nodemailer');
var fs = require('fs');
// package.json 設定的一些config資料
var smptCfg = require('../package.json').config.smtp;
// 設定於package.json
var mailService = nodemailer.createTransport({
host: smptCfg.host,
port: smptCfg.port,
});
exports.mailService = mailService;
var message = {
from: 'Sitronix IT Support<[email protected]>',
to: '[email protected]',
cc: '[email protected];[email protected];[email protected]',
subject: '[測試信] file worker testing mail',
// text: 'That was easy!',
html: "Dear Sir, <br><br> This is testing mail!!",
// 只需新增attachments配置項即可
attachments: [
{ // file on disk as an attachment
filename: 'testfile1M_3.txt',
path: '\\\\QA1\\SitronixApplication\\Test\\testfile1M_3.txt' // stream this file
},
{
// file on disk as an attachment
filename: 'testfile2M.txt',
path: '\\\\QA1\\SitronixApplication\\Test\\testfile2M.txt' // stream this file
}]
};
// 寄信
mailService.sendMail(message, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});