var mailer = require("nodemailer");
// Use Smtp Protocol to send Email
var smtpTransport = mailer.createTransport("SMTP",{
service: "Gmail",
auth: {
user: "gmail_id@gmail.com",
pass: "gmail_password"
}
});
var mail = {
from: "Yashwant Chavan <from@gmail.com>",
to: "to@gmail.com",
subject: "Send Email Using Node.js",
text: "Node.js New world for me",
html: "<b>Node.js New world for me</b>"
}
smtpTransport.sendMail(mail, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
smtpTransport.close();
});
client.sendString('<p>{{something}}</p>', {
to: ['someone@gmail.com', 'someone.else@gmail.com'],
subject: 'Some Subject',
preview': 'The first line',
something: 'this is what replaces that thing in the template'
}, done);
11 回答
Nodemailer基本上是一个模块,使您能够在Node.js中编程时轻松发送电子邮件 . 有一些关于如何在http://www.nodemailer.com/使用Nodemailer模块的很好的例子 . 有关如何安装和使用Nodemailer基本功能的完整说明,请参见此链接 .
我个人在使用npm安装Nodemailer时遇到了麻烦,所以我刚刚下载了源代码 . 有关npm安装和下载源的说明 .
这是一个非常简单的模块,我建议任何想要使用Node.js发送电子邮件的人 . 祝好运!
node-email-templates是一个更好的选择:https://github.com/niftylettuce/node-email-templates
它也支持Windows
看看emailjs
在浪费了大量时间尝试使用大型附件进行nodemailer工作之后,发现了emailjs并且从此开心 .
它支持使用普通的File对象发送文件,而不是像nodemailer所要求的那样使用巨大的Buffers . 意味着你可以将它链接到,例如,强大的将附件从html表单传递给邮件程序 . 它还支持排队..
总而言之,不知道为什么nodejitsu ppl选择了nodemailer来 Build 他们的版本,emailjs更加先进 .
使用nodemailer模块完成代码以发送电子邮件
@ JimBastard接受的答案似乎已过时,我看了一下,邮件库已经超过7个月未被触及,列出了几个错误,并且不再在npm注册 .
nodemailer当然看起来是最好的选择,但是在这个帖子的其他答案中提供的网址都是404' .
nodemailer声称支持轻松插入gmail,hotmail等,并且还有非常漂亮的文档 .
你总是可以使用AlphaMail( disclosure: I'm one of the developers behind it ) .
只需使用NPM安装:
注册一个AlphaMail帐户 . 获取令牌,然后您可以开始使用AlphaMail服务发送 .
在AlphaMail GUI(Dashboard)中,您将能够使用您发送的数据编辑模板:
模板以Comlang编写,它是专为电子邮件设计的简单模板语言 .
成熟,易于使用,并且如果不简单则具有许多功能:Nodemailer:https://github.com/andris9/nodemailer(注意正确的URL!)
Nodemailer模块是在node.js中发送电子邮件的最简单方法 .
试试这个示例示例表单:http://www.tutorialindustry.com/nodejs-mail-tutorial-using-nodemailer-module
附加信息:http://www.nodemailer.com/
npm 有几个包,但还没有达到1.0 . 最佳选择来自
npm list mail
:您肯定希望使用https://github.com/niftylettuce/node-email-templates,因为它支持nodemailer / postmarkapp并且内置了漂亮的异步电子邮件模板支持 .
campaign是一个用于在Node中发送电子邮件的综合解决方案,它带有一个非常简单的API .
你这样实例 .
要发送电子邮件,您可以使用Mandrill,这是免费且非常棒的 . 只需设置您的API密钥,如下所示:
(如果您想使用其他提供商发送电子邮件,请查看文档)
然后,当您要发送电子邮件时,您可以这样做:
GitHub回购有pretty extensive documentation .