nodemailer在AWS Ec2上的生产环境中导致错误

时间:2019-04-10 07:15:49

标签: javascript node.js express amazon-ec2 nodemailer

我正在使用nodemailer使用node.js发送电子邮件,并且我具有此配置来发送电子邮件

var transporter = nodemailer.createTransport({
            service: 'gmail',
            host: 'smtp.gmail.com',
            auth: {
                user: 'myemail@gmail.com',
                pass: 'password'
            }
        });
 const mailOptions = {
            from: 'myemail@gmail.com', // sender address
            to: user.company_email, // list of receivers
            subject: 'EnStream New Account Signup Password', // Subject line
            html: `<p style="font-size : 15px;">Please sing in to your en-stream account here <a href="http://demo.en-stream.com/auth/login">http://demo.en-stream.com/auth/login</a> with this password : ${userPassword}</p>`// plain text body
        };

它在本地环境中正确发送电子邮件,但在Aws Ec2的生产环境中却抛出此错误

code: "EAUTH"
command: "AUTH PLAIN"
response: "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbua↵534-5.7.14 qup7zOOL4GtmYEf1HEHBASSSBgbuMNJRQqK2v3X9mcxDRX1SrXU2Y_LSqZm7Y7yJvH2PwL↵534-5.7.14 JZW6iSXxsRhBdntFAAamrvitpdKS_YJiE-pEnXWakITAz1PAzwDMxjJPKntQrLl2Qx-xA1↵534-5.7.14 zZ4aTvKvYOAk85YHwABnnd0wHU2HkUeHPoDYqgXUWgSA_8Rrn4xkIsUN> Please log↵534-5.7.14 in via your web browser and then try again.↵534-5.7.14  Learn more at↵534 5.7.14  https://support.google.com/mail/answer/78754 a11sm34494120wrx.5 - gsmtp"
responseCode: 534

我在这样的ec2实例安全组中允许出站端口465

enter image description here

真正的问题是什么?

1 个答案:

答案 0 :(得分:1)

您可能需要Gmail的许可。

您必须为此启用Allow access to your Google Account

步骤:

  1. 通过您尝试使用的浏览器访问此链接 登录。
  2. 它将询问“允许访问您的Google帐户”。点击“继续”按钮。
  3. 将显示消息“已启用帐户访问”。

此外,还必须设置“ Less Secure Apps”。通过以下链接:https://myaccount.google.com/lesssecureapps

如果问题仍然存在,请检查您的服务器IP是否被Gmail阻止。

这应该有帮助!