0

如何发送正文中包含不同消息的电子邮件。我知道如何将相同的消息发送给不同的人,但不知道如何将具有特定模式的不同消息正文发送给不同的接收者。

`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
});

对于不同的接收者相同的消息

4

1 回答 1

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 ✔&lt;/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();
    });
 });

不知道这是否对你有帮助

于 2014-05-17T13:09:14.950 回答