[英]nodemailer Gmail SMTP not working on heroku
I am using nodemailer
to send mail with my test account我正在使用nodemailer
通过我的测试帐户发送邮件
It is a daily mailer这是每日邮递员
It works perfectly on the local instance as it is the same device and it was working a couple of days earlier它在本地实例上完美运行,因为它是同一台设备,并且它在几天前就开始工作了
NOTE: This is just a representation of the mailer program and there are different values in the actual codebase注意:这只是邮件程序的一个表示,实际代码库中有不同的值
My code我的代码
right-hand.js右手边.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应用程序.js
const rh = require(`./right-hand.js`);
rh.email("<h1>Hello World</h1>");
So to the main point Every day google says Unauthorised login prevented
Suspicious activity
etc...etc...所以重点是谷歌每天都说Unauthorised login prevented
Suspicious activity
等等......
Heroku logs 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]: }
What am I missing?我错过了什么?
I found the solution我找到了解决方案
It is using oauth 2.0 with googleapis它使用 oauth 2.0 和 googleapis
But still you are restricted by the api quotas但是你仍然受到 api 配额的限制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.