javascript - nodemailer 在 Aws Ec2 上的生产环境中导致错误

标签 javascript node.js express amazon-ec2 nodemailer

我正在使用 node.js 使用 nodemailer 发送电子邮件,我有这个配置来发送电子邮件

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

这里面真正的问题是什么?

最佳答案

您可能需要获得 Gmail 的许可。

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

步骤:

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

此外,必须允许设置“不太安全的应用程序”。通过此链接:https://myaccount.google.com/lesssecureapps .

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

这应该有帮助!

关于javascript - nodemailer 在 Aws Ec2 上的生产环境中导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55606781/

相关文章:

javascript - app.js 文件在被编辑后停止工作

javascript - 如何在 Angular 员工 component.html 上返回 EmployeeCode?

javascript - 对来自 Express 的响应使用react JSON.parse 语法错误

javascript - 我想了解passport js如何工作,特别是req.user以及数据如何填充

node.js - 如何在 Mongodb 聚合(组)中进行 $sum 和 $filter

javascript - HTML 未呈现 - Express

javascript - 加载图像后调整 HTML Canvas 大小

javascript - 当图表具有不同宽度时,同步 HighCharts 不起作用

node.js - NodeJS 子进程在 SIGINT 上终止

javascript - 在多个模块中需要(相同的实例)socket.io