javascript-Nodemailer和Amazon SES
作者:互联网
我的结构:
site
-- node_modules
---- nodemailer
-- webclient
---- js
------- controller.js
site/node_modules/nodemailer
site/webclient/js/controller.js
网站/webclient/js/controller.js:
var nodemailer = require('../../node_modules/nodemailer');
var transport = nodemailer.createTransport('SES', {
AWSAccessKeyID: 'xxx', // real one in code
AWSSecretKey: 'xxx', // real one in code
ServiceUrl: 'email-smtp.us-west-2.amazonaws.com'
});
var message = {
from: 'example@mail.com', // verified in Amazon AWS SES
to: 'example@mail.com', // verified in Amazon AWS SES
subject: 'testing',
text: 'hello',
html: '<p><b>hello</b></p>' +
'test'
};
transport.sendMail(message, function(error) {
if (error) {
console.log(error);
} else {
console.log('Message sent: ' + response.message);
}
});
该代码是控制器的一部分,该控制器中的所有其他功能都可以正常运行.
>我有什么想念的吗?
>也许我要求使用错误的nodemailer模块?
>或者传输应该是SMTP,而不是SES?
我被卡住了.
解决方法:
下面的代码是我使用的,并且对我有用.这是针对当前的NodeMailer.需要单独包括运输模块的地方.在以前的版本中,传输模块是内置的.
https://andrisreinman.com/nodemailer-v1-0/#migrationguide
var nodemailer = require('nodemailer');
var sesTransport = require('nodemailer-ses-transport');
var SESCREDENTIALS = {
accessKeyId : "accesskey" ,
secretAccessKey : "secretkey"
};
var transporter = nodemailer.createTransport(sesTransport({
accessKeyId: SESCREDENTIALS.accessKeyId,
secretAccessKey: SESCREDENTIALS.secretAccessKey,
rateLimit: 5
}));
var mailOptions = {
from: 'FromName <registeredMail@xxx.com>',
to: 'registeredMail@xyz.com', // list of receivers
subject: 'Amazon SES Template TesT', // Subject line
html: <p>Mail message</p> // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info);
}
});
标签:nodemailer,amazon-ses,javascript 来源: https://codeday.me/bug/20191029/1960424.html