Nodemailer Gmail SMTP 无法在 heroku 上运行

Nodemailer Gmail SMTP not working on heroku

我正在使用nodemailer发送邮件
它在本地实例上完美运行,因为它是同一台设备
注意:这只是邮件程序的表示,实际代码库中有不同的值
我的代码
nodule.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);
      }
    });
  }
}

app.js

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

问题

所以到了重点每天google说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]: }

我尝试过的

我错过了什么?

您可以尝试使用 google apis oauth 2.0 并将自己设置为测试人员并代表您发送邮件 docs