如何在正文中发送包含不同邮件的电子邮件。我知道如何向不同的人发送相同的消息,但不知道如何向不同的接收者发送具有特定模式的不同消息体。
`var mailOptions = {
from: "xyz <xyz@gmail.com>", // sender address
to: "abc@abc.com, lmn@lmn.com, akb@gmail.com", // list of receivers
subject: "Hello ", // Subject line
text: "Hello world ", // plaintext body
html: "<b>Hello world </b>" // html body
};`
// send mail with defined transport object
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
// if you don't want to use this transport object anymore, uncomment following line
//smtpTransport.close(); // shut down the connection pool, no more messages
});
为不同的接收者提供相同的消息
答案 0 :(得分:0)
使用https://github.com/caolan/async:
var async = require("async");
// setup e-mail data with unicode symbols
var mailOptions = {
from: "xyz <xyz@gmail.com>", // sender address
subject: "Hello ✔", // Subject line
text: "Hello world ✔", // plaintext body
html: "<b>Hello world ✔</b>" // html body
}
var toEmail = ["abc@abc.com", "lmn@lmn.com", "akb@gmail.com"];
// send mail with defined transport object
async.forEachLimit(toEmail,1,function(email,callback){
mailOptions["to"] = email;
//manipulate the text
mailOptions["text"] = "Hi" + email;
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
callback();
});
});
不知道这有助于你