smtp接口说明--使用nodejs通过smtp协议发信

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

smtp接口说明--使用nodejs通过smtp协议发信 [2017/03/22 03:52] (当前版本)
行 1: 行 1:
 +使用nodejs通过smtp协议发信
 +
 +// load nodemailer as follows
 +// npm install nodemailer --save
 +
 +var nodemailer = require('​nodemailer'​);​
 +
 +// create reusable transporter object using SMTP transport
 +var transporter = nodemailer.createTransport({
 +    "​host":​ "​smtp.bestedm.org",​
 +    "​port":​ 25,
 +    "​secureConnection":​ true, // use SSL
 +    "​auth":​ {
 +        "​user":​ '​username@userdomain',​ // user name
 +        "​pass":​ '​xxxxxxx' ​        // password
 +    }
 +});
 +
 +// NB! No need to recreate the transporter object. You can use
 +// the same transporter object for all e-mails
 +
 +// setup e-mail data with unicode symbols
 +var mailOptions = {
 +    from: '​NickName<​username@userdomain>',​ // sender address mailfrom must be same with the user
 +    to: '​x@x.com,​ xx@xx.com',​ // list of receivers
 +    cc:'​haha<​xxx@xxx.com>',​ // copy for receivers
 +    bcc:'​haha<​xxxx@xxxx.com>',​ // secret copy for receivers
 +    subject: '​Hello',​ // Subject line
 +    text: 'Hello world',​ // plaintext body
 +    html: '<​b>​Hello world</​b><​img src="​cid:​01"​ style="​width:​200px;​height:​auto">',​ // html body
 +    attachments:​ [
 +        {
 +            filename: '​text0.txt',​
 +            content: 'hello world!'​
 +        },
 +        {
 +            filename: '​text1.txt',​
 +            path: '​./​app.js'​
 +        },{
 +            filename:'​test.JPG',​
 +            path:'​./​Desert.jpg',​
 +            cid:'​01'​
 +       }
 +    ],
 +
 +};
 +
 +// send mail with defined transport object
 +transporter.sendMail(mailOptions,​ function(error,​ info){
 +    if(error){
 +        return console.log(error);​
 +    }
 +    console.log('​Message sent: ' + info.response);​
 +
 +});
 +
  
smtp接口说明--使用nodejs通过smtp协议发信.txt · 最后更改: 2017/03/22 03:52 (外部编辑)