如何从Heroku通过Nodemailer Gmail发送电子邮件?

xfb7svmp  于 2023-06-22  发布在  Node.js
关注(0)|答案(1)|浏览(209)

我不能使用Heroku发送电子邮件与Nodemailer。如果我在Localhost上发送请求,它可以工作,但当我尝试在Heroku中这样做时,我得到了下面的错误。

2020-07-20T15:57:12.346794+00:00 app[web.1]:     '534-5.7.14 db2zxU6IPdAWjsqy4cYGjB4Rv6dAq5CqOV8jd_fGPX8S-R0vsP-CKcCsmKYqBwCVhCdnL\n' +

2020-07-20T15:57:12.346795+00:00 app[web.1]:     '534-5.7.14 S2B1oDm_eEW0E4obWbTebMsf2BXprvCUviyFQQqVbFmhLgDFMV4qjgKjpaJaPUZ5>\n' +

2020-07-20T15:57:12.346795+00:00 app[web.1]:     '534-5.7.14 Please log in via your web browser and then try again.\n' +

2020-07-20T15:57:12.346795+00:00 app[web.1]:     '534-5.7.14  Learn more at\n' +

2020-07-20T15:57:12.346795+00:00 app[web.1]:     '534 5.7.14  https://support.google.com/mail/answer/78754 m7sm20190945qti.6 - gsmtp',

2020-07-20T15:57:12.346795+00:00 app[web.1]:   responseCode: 534,

2020-07-20T15:57:12.346796+00:00 app[web.1]:   command: 'AUTH PLAIN'

2020-07-20T15:57:12.346797+00:00 app[web.1]: }

2020-07-20T15:57:12.363186+00:00 app[web.1]: [2020-07-20 15:57:12] INFO  [XwRsbT31Bqs] Connection closed

我得到了那个错误
我正在使用:

const transporter = nodemailer.createTransport({
    host: 'https://motofrete-backend.herokuapp.com',
    service: "Gmail",
    logger: true,
});

transporter.verify(function (error, success) {
    if (error) {
        console.log(error);
    } else {
        console.log("Server is ready to take our messages", success);
    };
});

transporter.sendMail({
            from: 'teste <email@gmail.com>',
            to: email.to,
            auth: {
                user: process.env.email,
                pass: process.env.passMail,
                refreshToken: process.env.REFRESH_TOKEN,
                accessToken: process.env.ACCESS_TOKEN,
            },
rqqzpn5f

rqqzpn5f1#

允许不太安全的应用程序:如果您不使用两步验证,则可能需要允许安全性较低的应用访问您的帐户。
按照以下网址阅读如何做到这一点的说明。
https://support.google.com/mail/answer/7126229?visit_id=637308585317776650-2698520165&rd=2#cantsignin

相关问题