gpt4 book ai didi

node.js - 无法在 Node 中发送邮件,出现 UnhandledPromiseRejectionWarning 错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:12 24 4
gpt4 key购买 nike

发送邮件时出错:

(node:11928) UnhandledPromiseRejectionWarning: Error: Invalid login: 535 Authentication Failed

我尝试过nodemailer:

 //library.js 
const nodemailer = require("nodemailer");
module.exports
= {
transport:function(){
let transporter = nodemailer.createTransport({
host: "smtp.***.email",
port: 587,
secure: false,
auth: {
user: ****,
pass: ****
}
});
return transporter;
}

//controller.js
exports.sendemail = (require,res) => {
let mailOptions =
{
from: '"Fred Foo 👻" <foo@example.com>',
to: "baz@example.com",
subject: "Hello ✔",
text: "Hello world?",
html: "<b>Hello world?</b>"
};
transporter = transport.transporter();
let info = transporter.sendMail(mailOptions)
console.log("Message sent: %s", info.messageId);
}

Message sent: b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com

最佳答案

use same email at transporter and from on mail-options.
//library.js
const nodemailer = require("nodemailer");
module.exports = {
transport:function(){
let transporter = nodemailer.createTransport(
{
host: "smtp.***.email",
port: 587,
secure: false,
auth: {
user: 'foo@example.com',
pass: ****
}
});
return transporter; }}

//controller.js
exports.sendemail = (require,res) => {
let mailOptions =
{
from: '"Fred Foo 👻" <foo@example.com>',
to: "baz@example.com",
subject: "Hello ✔",
text: "Hello world?",
html: "<b>Hello world?</b>"
};
transporter = transport.transporter();
transporter.sendMail(mailOptions).then((info) =>
{
console.log(info);
return true;
}.catch(err =>
{
console.log("Error:", err);
return false;
});}

关于node.js - 无法在 Node 中发送邮件,出现 UnhandledPromiseRejectionWarning 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54211632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com