Sending emails using Mailgun with NodeMailer package

后端 未结 3 969
慢半拍i
慢半拍i 2021-02-02 11:01

A couple of days ago I realized that Google has changed the security of gmail accounts, particularly for the possibility of sending emails from applications. After Googling arou

3条回答
  •  误落风尘
    2021-02-02 11:43

    var nodemailer = require('nodemailer');
    // send mail with password confirmation
    var transporter = nodemailer.createTransport( {
        service:  'Mailgun',
        auth: {
         user: 'postmaster@sandboxXXXXXXXXXXXXXXXX.mailgun.org',
         pass: 'XXXXXXXXXXXXXXXX'   
        }
    });
    var mailOpts = {
        from: 'office@yourdomain.com',
        to: 'user@gmail.com',
        subject: 'test subject',
        text : 'test message form mailgun',
        html : 'test message form mailgun'
    };
    transporter.sendMail(mailOpts, function (err, response) {
        if (err) {
         //ret.message = "Mail error.";
        } else {
         //ret.message = "Mail send.";
        }
    });
    

提交回复
热议问题