![](/img/trans.png)
[英]How to send a result of query in email using nodemailer in node.js
[英]send email from node.js app using nodemailer
在我的Ubuntu(10.04)框中,我可以通过以下方式发送电子邮件:
echo "hello" | mail -s 'test email' my_gmail_nickname@gmail.com
当我尝试从同一台计算机上运行的node.js应用程序发送电子邮件时,它不起作用。
var nodemailer = require('nodemailer');
nodemailer.SMTP = {
host: 'localhost'
}
nodemailer.send_mail(
{
sender: 'me@example.com',
to:'my_gmail_nickname@gmail.com',
subject:'Hello!',
html: 'test',
body:'test'
},
function(error, success){
console.log(error);
console.log(success);
console.log('Message ' + success ? 'sent' : 'failed');
});
我有错误消息:
me@luc:~/gridteams/services/gpshop$ cat nohup.out
{ stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'ECONNREFUSED, Connection refused',
errno: 111,
code: 'ECONNREFUSED',
syscall: 'connect' }
null
sent
我看到连接被拒绝,但不明白为什么会收到此错误。 您认为缺失的部分是什么?
我认为您的问题是这样的:
命令行程序邮件使用名为/ usr / sbin / sendmail的二进制文件发送邮件。 sendmail是一个命令行程序,它将尝试传递邮件。 它使用到邮件基础结构的本地连接。
节点nodemailer将尝试连接到主机localhost上TCP端口25上不存在的SMTP服务器。 只需尝试使用telnet程序进行连接即可进行验证。
这是一台正在运行的服务器:
$ 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
如果您获得第二个,则说明您的SMTP出现问题,该问题未启动/启用,无法监听端口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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.