4

我正在尝试在我的 nodejs 应用程序中使用 nodemailer 发送电子邮件。我尝试使用 gmail 发送,一切正常,但是当我使用 Mandrill 作为我的 SMTP 提供程序时,我收到了身份验证错误。

这是我的代码:

var smtpTransport = nodemailer.createTransport("SMTP",{
    service: "Mandrill",
    auth: {
        user: "username@mydomain.com",
        pass: "*****"
    }
});

module.exports.sendEmail = function(to, subject, body, callback){
    smtpTransport.sendMail({
        from: "username@mydomain.com",
        to: to,
        subject: subject,
        html: body
    }, function(error, response){
        if(error){
            console.log(error); callback(error, response);
        }else{
            callback(null, response);
        }
    });
};

};

这就是我得到的错误

{ [AuthError: Invalid login - 435 4.7.8 Error: authentication failed:]
    name: 'AuthError',
        data: '435 4.7.8 Error: authentication failed:',
    stage: 'auth' }
4

1 回答 1

7

我遇到了类似的问题。在我的情况下,身份验证错误是因为 mandrill 不接受您的 mandrill 帐户密码作为 smtp 身份验证密码,而是您可以在仪表板上生成的 api 密钥。用户名与您的帐户用户名相同。产生误解可能是由于 mandrill 主页上的示例,但在 SMTP 和 API 凭据页面(一旦您登录)下明确提到 smtp 密码是 api 密钥。

希望这会有所帮助。

于 2014-06-17T04:20:25.470 回答