从localhost发送的带有nodemailer的电子邮件不会发送

时间:2014-06-19 20:25:50

标签: javascript node.js nodemailer

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

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

回拨功能日志&#34;已发送&#34;但电子邮件永远不会发送。我按照本教程http://www.thihaz.com/?p=218

进行了操作

我还需要另外设置smth吗?

1 个答案:

答案 0 :(得分:2)

您可以nodemailer照顾相应的服务器,例如Gmail:

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

然后执行:

transport.sendMail()

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