[英]Node.js: Send e-mails using AWS SES
Is there a stable module for Amazon SES in Node.js? Node.js 中是否有适用于 Amazon SES 的稳定模块?
Thanks谢谢
There is a new official AWS SDK for Node.js providing an API for every services. 有一个新的官方AWS SDK for Node.js为每个服务提供API。 You should give it a try :
你应该试一试:
http://aws.amazon.com/sdkfornodejs/ http://aws.amazon.com/sdkfornodejs/
Here's what worked for me (optional parameters are commented out; constructed from the AWS JavaScript SDK SES Documentation ): 这些对我有用(可选参数已注释掉;从AWS JavaScript SDK SES文档构建):
var SES = require('aws-sdk/clients/ses');
var ses = new SES({
accessKeyId: "MY_ACCESS_KEY_ID",
secretAccessKey: "MY_SECRET_ACCESS_KEY"
apiVersion: '2010-12-01',
region: "us-east-1",
});
var params = {
Destination: {
// BccAddresses: [
// 'STRING_VALUE',
// /* more items */
// ],
// CcAddresses: [
// 'STRING_VALUE',
// /* more items */
// ],
ToAddresses: [
'MY_PERSONAL_EMAIL@gmail.com',
]
},
Message: {
Body: {
Html: {
Data: '<b>hello world</b>',
Charset: 'utf-8'
},
Text: {
Data: 'hello world',
Charset: 'utf-8'
}
},
Subject: {
Data: 'hello subject',
Charset: 'utf-8'
}
},
Source: 'MY_EMAIL_REGISTERED_WITH_SES@MYDOMAIN.COM',
// ConfigurationSetName: 'STRING_VALUE',
// ReplyToAddresses: [
// 'STRING_VALUE',
// /* more items */
// ],
// ReturnPath: 'STRING_VALUE',
// ReturnPathArn: 'STRING_VALUE',
// SourceArn: 'STRING_VALUE',
// Tags: [
// {
// Name: 'STRING_VALUE',
// Value: 'STRING_VALUE'
// },
// /* more items */
// ]
};
ses.sendEmail(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
This one is your best bet 这是你最好的选择
https://github.com/livelycode/aws-lib https://github.com/livelycode/aws-lib
Use the Official aws-sdk
node module: https://www.npmjs.com/package/aws-sdk 使用官方
aws-sdk
节点模块: https : //www.npmjs.com/package/aws-sdk
The API docs are good: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html API文档很好: http : //docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html
But, if you need a complete step-by-step example , we wrote one: https://github.com/dwyl/sendemail 但是,如果您需要一个完整的分步示例 ,我们写了一个: https : //github.com/dwyl/sendemail
( we are using this in several projects and it works well for us ) ( 我们在几个项目中使用它,它对我们很有用 )
var express = require('express');
var app = express();
var nodemailer = require('nodemailer');
var AWS = require('aws-sdk');
var smtpConfig = {
host: 'email-smtp.us-west-2.amazonaws.com',
port: 465,
secure: true, // use SSL
auth: {
user: 'userName',
pass: 'password'
}
};
var transport = nodemailer.createTransport(smtpConfig);
app.get('/sendMail', function (req, res) {
transport.sendMail({
from: 'youremail@localhost.com',
to: 'recipient@localhost.com',
subject: 'My Amazon SES Simple Email',
text: 'Amazon SES is cool'
},function(error, data){
if(error){
res.status(403).json({message:error});
}
if(data){
res.end('mail sent');
}
});
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
You could also try AwsSum which gives you a lot more help than the other libraries. 您也可以尝试AwsSum,它比其他库提供更多帮助。
Note: I'm the author of AwsSum and again, it's actively maintained, unlike some of the other AWS libraries out there for Node.js. 注意:我是AwsSum的作者,并且它是主动维护的,与Node.js的其他一些AWS库不同。 :)
:)
For reference, widely used NodeMailer module can be used to send SES email.作为参考,可以使用广泛使用的 NodeMailer 模块发送 SES email。 Can check out this gist to send email with zip attachment: https://gist.github.com/munim/02e1bc10bf4e0fbb17c5bf6689906a8a
Can check out this gist to send email with zip attachment: https://gist.github.com/munim/02e1bc10bf4e0fbb17c5bf6689906a8a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.