【发布时间】:2011-05-06 01:11:23
【问题描述】:
我最近开始编写我的第一个 node.js。但是,我发现我无法创建直接发送到我的电子邮件的联系我表单,因为我无法从节点中找到任何能够发送电子邮件的模块。
有人知道 node.js 电子邮件库或示例联系表单脚本吗?
【问题讨论】:
-
结帐:AWS-SES 为 ec2 应用程序免费发送 62000 封电子邮件。
我最近开始编写我的第一个 node.js。但是,我发现我无法创建直接发送到我的电子邮件的联系我表单,因为我无法从节点中找到任何能够发送电子邮件的模块。
有人知道 node.js 电子邮件库或示例联系表单脚本吗?
【问题讨论】:
使用nodemailer模块发送电子邮件的完整代码
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();
});
【讨论】:
Nodemailer way 比node-email-templates 更易于使用。也许是因为我只是想发送基本的纯文本/基本 html 电子邮件,但我发现 node-email-templates 需要更多设置,而 Nodemailer 只需 2 分钟即可启动并运行。
Nodemailer 基本上是一个模块,可让您在使用 Node.js 编程时轻松发送电子邮件。 http://www.nodemailer.com/ 有一些很好的例子来说明如何使用 Nodemailer 模块。有关如何安装和使用 Nodemailer 基本功能的完整说明包含在此链接中。
我个人在使用 npm 安装 Nodemailer 时遇到了麻烦,所以我只下载了源代码。有关于 npm 安装和下载源代码的说明。
这是一个非常简单易用的模块,我会向任何想要使用 Node.js 发送电子邮件的人推荐它。祝你好运!
【讨论】:
Nodemailer 模块是在 node.js 中发送电子邮件的最简单方法。
试试这个示例表单:http://www.tutorialindustry.com/nodejs-mail-tutorial-using-nodemailer-module
【讨论】:
campaign 是一个在 Node 中发送电子邮件的综合解决方案,它带有一个非常简单的 API。
你这样实例化它。
var client = require('campaign')({
from: 'you@gmail.com'
});
要发送电子邮件,您可以使用Mandrill,这是免费且很棒的。只需设置您的 API 密钥,如下所示:
process.env.MANDRILL_APIKEY = '<your api key>';
(如果您想使用其他提供商发送电子邮件,请查看文档)
然后,当你想发送电子邮件时,你可以这样做:
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);
GitHub 存储库有 pretty extensive documentation。
【讨论】:
你总是可以使用AlphaMail(披露:我是它背后的开发者之一)。
只需使用NPM 安装:
npm install alphamail
注册一个 AlphaMail 帐户。获取令牌,然后您就可以开始使用 AlphaMail 服务发送了。
var alphamail = require('alphamail');
var emailService = new alphamail.EmailService()
.setServiceUrl('http://api.amail.io/v1/')
.setApiToken('YOUR-ACCOUNT-API-TOKEN-HERE');
var person = {
id: 1234,
userName: "jdoe75",
name: {
first: "John",
last: "Doe"
},
dateOfBirth: 1975
};
emailService.queue(new alphamail.EmailMessagePayload()
.setProjectId(12345) // ID of your AlphaMail project (determines template, options, etc)
.setSender(new alphamail.EmailContact("Sender Company Name", "from@example.com"))
.setReceiver(new alphamail.EmailContact("John Doe", "to@example.org"))
.setBodyObject(person) // Any serializable object
);
在 AlphaMail GUI (Dashboard) 中,您将能够使用您发送的数据编辑模板:
<html>
<body>
<b>Name:</b> <# payload.name.last " " payload.name.first #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.id != null) { #>
<a href="http://company.com/sign-up">Sign Up Free!</a>
<# } else { #>
<a href="http://company.com/login?username=<# urlencode(payload.userName) #>">Sign In</a>
<# } #>
</body>
</html>
模板是用Comlang编写的,这是一种专门为电子邮件设计的简单模板语言。
【讨论】:
node-email-templates 是一个更好的选择: https://github.com/niftylettuce/node-email-templates
它也支持windows
【讨论】:
node-email-templates 启动并运行。我只想将它用作我初始化然后用于发送的对象。无法让它工作。放弃。
你肯定想使用https://github.com/niftylettuce/node-email-templates,因为它支持 nodemailer/postmarkapp 并且内置了漂亮的异步电子邮件模板支持。
【讨论】:
成熟,易于使用,如果简单还不够的话,还有很多功能: Nodemailer:https://github.com/andris9/nodemailer(注意正确的 url!)
【讨论】:
@JimBastard 接受的答案似乎过时了,我看了看,邮件程序库已经超过 7 个月没有被触及,列出了几个错误,并且不再在 npm 中注册。
nodemailer 看起来确实是最好的选择,但是在此线程的其他答案中提供的 url 都是 404'ing。
nodemailer 声称支持 gmail、hotmail 等的简单插件,并且还有非常漂亮的文档。
【讨论】:
npm 有几个包,但还没有达到 1.0。来自npm list mail的最佳选择:
email@0.2.2
mail@0.1.1
mailer@0.3.0
【讨论】:
查看emailjs
在尝试使 nodemailer 处理大型附件浪费了大量时间之后,发现 emailjs 并从此快乐。
它支持使用普通的 File 对象发送文件,而不是像 nodemailer 需要的巨大的 Buffers。意味着您可以将其链接到,例如,将附件从 html 表单传递到邮件程序。它还支持排队..
总而言之,不知道为什么 nodejitsu ppl 选择 nodemailer 作为他们版本的基础,emailjs 只是更高级。
【讨论】: