emailjs不工作
我尝试使用emailjs( https://github.com/eleith/emailjs )发送电子邮件与nodejs,但是,它给了我一个错误:{[错误:连接到smtp服务器时,超时]代码:4, smtp:undefined}
我试图使用Hotmail,但我可以使用其他,我只想这个工作。 有什么想法吗?
var email = require("emailjs"); var server = email.server.connect({ user: "xxx@hotmail.com", password:"xxxyyyy", host: "smtp-mail.live.com", ssl: true }); // send the message and get a callback with an error or details of the message that was sent server.send({ text: "i hope this works", from: "you <xxxxxx@hotmail.com>", to: "someone <zzzzz@hotmail.com>", //cc: "else <else@your-email.com>", subject: "testing emailjs" }, function(err, message) { console.log(err || message); });
我使用下面的代码(使用gmail)进行testing,它正在工作:
var email = require('emailjs'); var server = email.server.connect({ user: 'nodejsiscool@gmail.com', password: 'stackoverflow', host: 'smtp.gmail.com', ssl: true }); server.send({ text: 'Hey howdy', from: 'NodeJS', to: 'Wilson <wilson.balderrama@gmail.com>', cc: '', subject: 'Greetings' }, function (err, message) { console.log(err || message); });
在我的控制台输出是:
{ attachments: [], alternative: null, header: { 'message-id': '<1433256538447.0.5970@Wilsons-MacBook-Pro.local>', date: 'Tue, 02 Jun 2015 10:48:58 -0400', from: '=?UTF-8?Q?NodeJS?= <>', to: '=?UTF-8?Q?Wilson?= <wilson.balderrama@gmail.com>', cc: '', subject: '=?UTF-8?Q?Greetings?=' }, content: 'text/plain; charset=utf-8', text: 'Hey howdy' }
事实上,我已收到我的收件箱中的电子邮件。
我怀疑你应该使用主机smtp.live.com而不是smtp-mail.live.com
注意:使用的帐户(nodejsiscool@gmail.com)是我为testing目的而创build的有效帐户。
使用Gmail
第一 :必须激活使用安全性较低的应用程序,风险自负,如Gmail文档中所述。 我使用了一个对我的testing不是很重要的帐户:
https://myaccount.google.com/u/2/lesssecureapps?pageId=none
后:
var email = require("emailjs"); var server = email.server.connect({ user: "YOUR_ACCOUNT@gmail.com", password:"YOUR_PASSWORD", host: "smtp.gmail.com", ssl: true }); server.send({ text: "Hello world", from: "YOUR_NAME <YOUR_ACCOUNT@gmail.com>", to: "FRIEND_NAME <FRIEND_ACCOUNT@gmail.com>", subject: "Hello" }, function(err, message) { console.log(err || message); });
附加说明:关于如何在Gmail收件箱中设置“from”和显示的名称:
例1:
设置“从”只有名称。
from: "YOUR_NAME", // Only name
在收件箱中显示<>
YOUR_NAME <> Hello 18:11
例2:
设置“从”与名字和emial。
from: "YOUR_NAME <YOUR_ACCOUNT@gmail.com>", // Name and email
在收件箱中不显示<>
YOUR_NAME Hello 18:11
确保你正确链接的电子邮件文件(检查无效的电子邮件),否则将无法正常工作。
//Email stuff var email = require("./node_modules/emailjs/email"); var server = email.server.connect({ user: "EMAIL@gmail.com", password:"INSERTPASSWORDHERE", host: "smtp.gmail.com", ssl: true }); //If button is clicked then send email server.send({ text: 'Hello World! \n\n Regards,\n INSERTNAMEHERE \n', from: 'Name', to: 'Name <EMAIL@gmail.com>', cc: '', subject: '' }, function (err, message) { console.log(err || message); });