我试图通过nodemailer发送电子邮件没有SMTP传输.所以我做到了:
var mail = require("nodemailer").mail; mail({ from: "Fred Foo ✔ <foo@blurdybloop.com>",// sender address to: "******@gmail.com",// list of receivers subject: "Hello ✔",// Subject line text: "Hello world ✔",// plaintext body html: "<b>Hello world ✔</b>" // html body });
但是当我跑步的时候我得到:
> node sendmail.js Queued message #1 from foo@blurdybloop.com,to vinz243@gmail.com Retrieved message #1 from the queue,reolving gmail.com gmail.com resolved to gmail-smtp-in.l.google.com for #1 Connecting to gmail-smtp-in.l.google.com:25 for message #1 Failed processing message #1 Message #1 requeued for 15 minutes Closing connection to the server Error: read ECONNRESET at errnoException (net.js:901:11) at TCP.onread (net.js:556:19)
我在windows 7 32.
编辑
这似乎是一个Windows相关的bug,它在linux上工作
编辑#2
在git shell上,如果我输入telnet smtp.gmail 587,这里被阻止:
220 mx.google.com ESMTP f7...y.24 -gsmtp
解决方法
从您的示例输出,似乎连接到错误的端口25,打开的gmail smtp端口为SSL为465,其他587 TLS.
Nodemailer根据电子邮件域检测到正确的配置,在您的示例中,您尚未设置传输器对象,因此它使用配置的默认端口25.要更改端口在选项中指定的类型.
以下是应用于gmail的小例子:
var nodemailer = require('nodemailer'); // Create a SMTP transport object var transport = nodemailer.createTransport("SMTP",{ service: 'Gmail',auth: { user: "test.nodemailer@gmail.com",pass: "Nodemailer123" } }); console.log('SMTP Configured'); // Message object var message = { // sender info from: 'Sender Name <sender@example.com>',// Comma separated list of recipients to: '"Receiver Name" <nodemailer@disposeBox.com>',// Subject of the message subject: 'Nodemailer is unicode friendly ✔',// plaintext body text: 'Hello to myself!',// HTML body html:'<p><b>Hello</b> to myself <img src="cid:note@node"/></p>'+ '<p>Here\'s a nyan cat for you as an embedded attachment:<br/></p>' }; console.log('Sending Mail'); transport.sendMail(message,function(error){ if(error){ console.log('Error occured'); console.log(error.message); return; } console.log('Message sent successfully!'); // if you don't want to use this transport object anymore,uncomment following line //transport.close(); // close the connection pool });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。