繁体   English   中英

nodemailer Gmail SMTP在heroku上不起作用

[英]nodemailer Gmail SMTP not working on heroku

我正在使用nodemailer通过我的测试帐户发送邮件
这是每日邮递员
它在本地实例上完美运行,因为它是同一台设备,并且它在几天前就开始工作了
注意:这只是邮件程序的一个表示,实际代码库中有不同的值
我的代码
右手边.js

const env = require("dotenv").config();
const nodemailer = require("nodemailer");
module.exports = {
  email: (html) => {
    var mail = nodemailer.createTransport({
      service: "gmail",
      auth: {
        user: "notanactualmail@gmail.com",
        pass: process.env.DEMO_ACCOUNT_PASSWORD
      }
    });

    var mailOptions = {
      from: "notanactualmail@gmail.com",
      to: process.env.TARGET_MAIL_ID,
      subject:
        "my title",
      html: html
    };

    mail.sendMail(mailOptions, (error, info) => {
      if (error) {
        console.log(error);
      }
    });
  }
}

应用程序.js

const rh = require(`./right-hand.js`);
rh.email("<h1>Hello World</h1>");

问题

所以重点是谷歌每天都说Unauthorised login prevented Suspicious activity等等......
Heroku 日志

2021-10-08T03:24:30.383820+00:00 heroku[web.1]: Starting process with command `node app.js`
2021-10-08T03:24:31.277868+00:00 app[web.1]: app is listening on port 19616
2021-10-08T03:24:32.059451+00:00 heroku[web.1]: State changed from starting to up
2021-10-08T03:24:32.726090+00:00 heroku[router]: at=info method=GET path="/autotrg/ifttt/auth/<Hardcoded name>" host=myapp.herokuapp.com request_id=0032f1f2-7641-475c-85eb-70e1d7d94fe0 fwd="45.248.22.6" dyno=web.1 connect=0ms service=6ms status=304 bytes=149 protocol=https
2021-10-08T03:24:34.224740+00:00 app[web.1]: Error: Invalid login: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt
2021-10-08T03:24:34.224757+00:00 app[web.1]: 534-5.7.14 suR76UfS5DkBscwE1tOwUYwx2Z6T5MR13HZ8QXHGtOMTfYBSdNVVOvhVItO5_3XwC-NYO
2021-10-08T03:24:34.224758+00:00 app[web.1]: 534-5.7.14 gerVJfsXtIw9zM5OALS3cng_HqJZOQRp5pr1ZyB7xPF7kbXcX8whhc2BDOtoMxsC>
2021-10-08T03:24:34.224758+00:00 app[web.1]: 534-5.7.14 Please log in via your web browser and then try again.
2021-10-08T03:24:34.224759+00:00 app[web.1]: 534-5.7.14  Learn more at
2021-10-08T03:24:34.224759+00:00 app[web.1]: 534 5.7.14  https://support.google.com/mail/answer/78754 l19sm1065983qkk.12 - gsmtp
2021-10-08T03:24:34.224759+00:00 app[web.1]:     at SMTPConnection._formatError (/app/node_modules/nodemailer/lib/smtp-connection/index.js:784:19)
2021-10-08T03:24:34.224759+00:00 app[web.1]:     at SMTPConnection._actionAUTHComplete (/app/node_modules/nodemailer/lib/smtp-connection/index.js:1536:34)
2021-10-08T03:24:34.224760+00:00 app[web.1]:     at SMTPConnection.<anonymous> (/app/node_modules/nodemailer/lib/smtp-connection/index.js:540:26)
2021-10-08T03:24:34.224760+00:00 app[web.1]:     at SMTPConnection._processResponse (/app/node_modules/nodemailer/lib/smtp-connection/index.js:947:20)
2021-10-08T03:24:34.224760+00:00 app[web.1]:     at SMTPConnection._onData (/app/node_modules/nodemailer/lib/smtp-connection/index.js:749:14)
2021-10-08T03:24:34.224760+00:00 app[web.1]:     at TLSSocket.SMTPConnection._onSocketData (/app/node_modules/nodemailer/lib/smtp-connection/index.js:189:44)
2021-10-08T03:24:34.224761+00:00 app[web.1]:     at TLSSocket.emit (events.js:400:28)
2021-10-08T03:24:34.224761+00:00 app[web.1]:     at addChunk (internal/streams/readable.js:293:12)
2021-10-08T03:24:34.224762+00:00 app[web.1]:     at readableAddChunk (internal/streams/readable.js:267:9)
2021-10-08T03:24:34.224762+00:00 app[web.1]:     at TLSSocket.Readable.push (internal/streams/readable.js:206:10) {
2021-10-08T03:24:34.224762+00:00 app[web.1]:   code: 'EAUTH',
2021-10-08T03:24:34.224762+00:00 app[web.1]:   response: '534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt\n' +
2021-10-08T03:24:34.224762+00:00 app[web.1]:     '534-5.7.14 suR76UfS5DkBscwE1tOwUYwx2Z6T5MR13HZ8QXHGtOMTfYBSdNVVOvhVItO5_3XwC-NYO\n' +
2021-10-08T03:24:34.224763+00:00 app[web.1]:     '534-5.7.14 gerVJfsXtIw9zM5OALS3cng_HqJZOQRp5pr1ZyB7xPF7kbXcX8whhc2BDOtoMxsC>\n' +
2021-10-08T03:24:34.224763+00:00 app[web.1]:     '534-5.7.14 Please log in via your web browser and then try again.\n' +
2021-10-08T03:24:34.224763+00:00 app[web.1]:     '534-5.7.14  Learn more at\n' +
2021-10-08T03:24:34.224763+00:00 app[web.1]:     '534 5.7.14  https://support.google.com/mail/answer/78754 l19sm1065983qkk.12 - gsmtp',
2021-10-08T03:24:34.224764+00:00 app[web.1]:   responseCode: 534,
2021-10-08T03:24:34.224764+00:00 app[web.1]:   command: 'AUTH PLAIN'
2021-10-08T03:24:34.224764+00:00 app[web.1]: }

我试过的

我错过了什么?

我找到了解决方案
它使用 oauth 2.0 和 googleapis
但是你仍然受到 api 配额的限制

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM