Luc*_*Luc 2 sendmail node.js nodemailer
从我的ubuntu(10.04)框中,我没有问题发送电子邮件:
echo "hello" | mail -s 'test email' my_gmail_nickname@gmail.com
Run Code Online (Sandbox Code Playgroud)
当我尝试从同一台机器上运行的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');
});
Run Code Online (Sandbox Code Playgroud)
我有错误消息:
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
Run Code Online (Sandbox Code Playgroud)
我看到连接被拒绝但不明白我为什么会收到此错误.你觉得缺少什么?
我认为你的问题是这样的:
命令行程序邮件使用名为/ usr/sbin/sendmail的二进制文件来发送邮件.sendmail是一个命令行程序,它将尝试传递邮件.它使用与邮件基础结构的本地连接.
节点nodemailer将尝试连接到TCP端口25上不存在的主机localhost上的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.
Run Code Online (Sandbox Code Playgroud)
这里没有服务器运行:
$ telnet localhost 25
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
Run Code Online (Sandbox Code Playgroud)
如果你得到第二个,你的SMTP有问题,没有启动/启用侦听端口25 - 这是默认设置(出于安全原因).您需要先配置它.
或者 - 根据nodemail文档,您也可以使用sendmail二进制文件:
Run Code Online (Sandbox Code Playgroud)'sendmail' alternative Alternatively if you don't want to use SMTP but the sendmail然后命令将属性sendmail设置为true(如果命令不在默认路径中,则设置为sendmail的路径).
Run Code Online (Sandbox Code Playgroud)nodemailer.sendmail = true; or nodemailer.sendmail = '/path/to/sendmail'; If sendmail is set, then SMTP options are discarded.
| 归档时间: |
|
| 查看次数: |
11775 次 |
| 最近记录: |