代码如下:
var nodemailder = require('nodemailer');
var from = nodemailder.createTransport({
service: "gmail",
auth:{
user: 'user***@gmail.com',
pass: 'pass***'
}
});
var options = {
from: 'user***@gmail.com',
to: 'user***@gmail.com',
subject: 'sometext',
text: 'messageContext',
};
from.sendMail(options, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});如果我使用Windows -它可以工作,当我尝试在Ubuntu (16)上启动时-我没有收到任何错误消息等,但邮件没有收到。
发布于 2021-01-26 01:57:01
如果是这种情况,我相信SMTP服务无法连接到端口25上的连接。
运行服务器将如下所示:
$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 xxxx.de ESMTP Postfix
QUIT
221 2.0.0 Bye
Connection closed by foreign host.如果没有服务器在此端口上侦听,它将如下所示:
$ telnet localhost 25
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused这意味着您的服务可能未运行或未启用。您需要首先在端口25上启用/运行此服务。
此外,根据nodemail文档,您还可以使用sendmail二进制文件:
'sendmail' alternative
Alternatively if you don't want to use SMTP but the sendmail命令然后将属性sendmail设置为true (如果该命令不在默认路径中,则将其设置为sendmail的路径)。
nodemailer.sendmail = true;
or
nodemailer.sendmail = '/path/to/sendmail';
If sendmail is set, then SMTP options are discarded. https://stackoverflow.com/questions/65888093
复制相似问题