gpt4 book ai didi

node.js - nodejs smtp-server 电子邮件已发送但未收到

转载 作者:太空宇宙 更新时间:2023-11-03 21:51:28 25 4
gpt4 key购买 nike

const nodemailer = require('nodemailer');

const SMTPServer = require("smtp-server").SMTPServer;

const server = new SMTPServer({
onAuth(auth, session, callback) {
if (auth.username !== "test" || auth.password !== "password") {
return callback(new Error("Invalid username or password"));
}
console.log(mailOptions.text);
callback(null, {
user: "test"

}); // where 123 is the user id or similar property
}
});

server.on("error", err => {
console.log("Error %s", err.message);
});

server.listen(26);


var transporter = nodemailer.createTransport({
host: "MYDOMAINNAME/IP",
port: 26,
secure: false,
auth: {
user: "test",
pass: "password"
},
tls: {
rejectUnauthorized: false
}
});

var mailOptions = {
from: '"MYSITENAME"<info@MYDOMAIN.com>',
to: 'ADRESS@TLD.com',
subject: 'Sending Email using Node.js',
text: 'That was easy!'
};

transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log("sendmail" + error);
} else {
console.log('Email sent: ' + info.response);
}
});

输出为:那很简单!电子邮件已发送:250 OK:消息已排队

我只想将带有输入变量的邮件作为文本从我的域名发送到普通的 Gmail 地址;gmail/或任何其他地址未收到邮件;检查垃圾邮件文件夹;

最佳答案

对于遇到同样问题但使用 Nodemailer 的 transporter 方式的人,我通过将服务器的 name 添加到 Transporter 对象中解决了这个问题。


const transportObj = {
name: credentials.host, // in my case, the host and the name are the same
host: credentials.host,
port: credentials.port,
secure: true,
auth: {
user: credentials.user,
pass: credentials.pass
},
}

const transporter = nodemailer.createTransport(transportObj)

transporter.sendMail(...)

此解决方案相关 here

关于node.js - nodejs smtp-server 电子邮件已发送但未收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54833249/

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