nodemailer 续
之前对nodemailer做了一个简单的了解,这篇文章主要研究一下如何添加附加文件
测试代码
//Created by yyrdl on 2015/10/2.
var nodemailer = require('nodemailer');
var smtpPool=require("nodemailer-smtp-pool");
var tool=require("./readFile");
var options={
"service":"QQ",
"auth":{
"user":"xxxxx@qq.com",
"pass":"xxxxxx"
},
"maxConnections":10,
"secure":true
};
var transporter = nodemailer.createTransport(smtpPool(options));
transporter.sendMail({
from:'xxxxx@qq.com',
to: 'xxxxxxxxx@163.com',
subject: 'hello',
html: "<img src='cid:01' style='width:200px;height:auto'>",
"attachments":[{
"filename":"just_give_me_a_reason.mp3",
"path":"./justGiveMeAReason.mp3"
},{
"filename":"test.txt",
"content":"测试可写的文件"
},{
"filename":"test.JPG",
"path":"./test.JPG",
"cid":"01"
}]
},function(err,res){
if(err){
console.log(err);
}else{
console.log(res);
}
});
注解
该代码所发的邮件中包含三个文件,都放在attachments里,让我一一道来