const transporter = nodemailer.createTransport({
source: 'gmail',
auth: {
user: process.env.EMAIL,
pass: process.env.EMAIL_PASSWORD
},
});
const mailoptions = {
from:`Anshul kumar <${process.env.EMAIL}>`,
to: Email,
subject: "Reset your Password",
text: "hi welcome",
html: `<a href="http://localhost:5000/password/resetpassword/${newid}">click on this link to reset your password</a>`,
};
transporter.sendMail(mailoptions, (error, info) => {
if (error) {
console.log(error);
res.status(500).json({ message: "can not send email", success: false });
} else {
res
.status(200)
.json({ message: "email sent successfully", success: true });
}
});
这就是错误:
错误:连接ECONNREFUSED 127.0.0.1:587 在 TCPConnectWrap.afterConnect [作为未完成] (节点:net:1494:16) { 错误号:-4078, 代码:'ESOCKET', 系统调用:'连接', 地址:'127.0.0.1', 端口:587, 命令:'CONN' }
当我使用主机作为“spmt-gmail.com”时出现此错误
Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials je10-20020a170903264a00b001bc2831e1a9sm268100plb.90 - gsmtp
at SMTPConnection._formatError (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:790:19)
at SMTPConnection._actionAUTHComplete (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:1564:34)
at SMTPConnection.<anonymous> (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:546:26)
at SMTPConnection._processResponse (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:969:20)
at SMTPConnection._onData (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:755:14)
at SMTPConnection._onSocketData (C:\Users\anshul\Desktop\full stack expense tracker\node_modules\nodemailer\lib\smtp-connection\index.js:193:44)
at TLSSocket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
code: 'EAUTH',
response: '535-5.7.8 Username and Password not accepted. Learn more at\n' +
'535 5.7.8 https://support.google.com/mail/?p=BadCredentials je10-20020a170903264a00b001bc2831e1a9sm268100plb.90 - gsmtp',
responseCode: 535,
command: 'AUTH PLAIN'
}
确保您使用的 SMTP 服务器是
smtp.gmail.com
并且您通过端口 587(启用 TLS/STARTTLS)或 465(启用 SSL)发送。如果您的 Gmail 帐户启用了两步验证,请继续使用应用程序密码。