0

我已经设置了这样的电子邮件发送:

        nodemailer = require("nodemailer");
...
            nodemailer.SMTP = {
                host: 'smtp.gmail.com', // required
                port: 465, // optional, defaults to 25 or 465
                domain: 'smtp.gmail.com', // domain used by client to identify itself to server
                authentication: 'login', // optional, false by default
                user: '1*******@gmail.com', // used only when use_authentication is true
                pass: '*******'  // used only when use_authentication is true
            }

            // send an e-mail
            nodemailer.send_mail(
                // e-mail options
                {
                    sender: '1*******@gmail.com',
                    to:'2*******@gmail.com',
                    subject:'Hello!',
                    html: '<p><b>Hi,</b> how are you doing?</p>',
                    body:'Hi, how are you doing?'
                },
                // callback function
                function(error, success){
                    console.log('Message ' + success ? 'sent' : 'failed');
                }

回调函数记录“已发送”,但从未发送过电子邮件。我按照本教程http://www.thihaz.com/?p=218

我必须另外设置吗?

4

1 回答 1

2

您可以让nodemailer处理相应的服务器,例如 Gmail:

var smtpTransport = nodemailer.createTransport("SMTP",{
    auth: {
        user: "gmail.user@gmail.com", // service is detected from the username
        pass: "userpass"
    }
});

然后做:

transport.sendMail()

这应该让你走上正确的道路。

于 2014-06-19T21:21:21.220 回答