[英]Nodemailer is not able to send mail using aws on production server
I am getting the problem while sending mails through nodemailer and AWS. 我通过nodemailer和AWS发送邮件时遇到问题。 Following are the my settings :
以下是我的设置:
var transporter = nodemailer.createTransport("SMTP", smtpTransport({
host: 'email-smtp.us-west-2.amazonaws.com',
service: 'SES',
port: 25,
secure: true,
debug: true,
auth: {
user: 'XXX',
pass: 'XXX'
}
}));
Mail sending code: 邮件发送代码:
transporter.sendMail({
from: xxx@xxx.com,
to: xxx@xxx.com,
subject: 'XXX',
html: 'XXX'
}, function(error, response) {
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
});
I am getting following error: 我收到以下错误:
{ [Error: connect ECONNREFUSED 127.0.0.1:25]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 25,
stage: 'init' }
Here's what my transporter object look like when I printed it : 这是我打印时我的运输车对象的样子:
Transport {
options:
SMTPTransport {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
options:
{ host: 'email-smtp.us-east-1.amazonaws.com',
service: 'SES',
port: 465,
secure: true,
debug: true,
auth: [Object] },
logger: { info: [Function], debug: [Function], error: [Function] },
name: 'SMTP',
version: '2.4.1[client:2.3.1]',
maxConnections: 5,
maxMessages: Infinity },
transportType: 'SMTP',
dkimOptions: false,
transport:
SMTPTransport {
options:
SMTPTransport {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
options: [Object],
logger: [Object],
name: 'SMTP',
version: '2.4.1[client:2.3.1]',
maxConnections: 5,
maxMessages: Infinity },
pool:
SMTPConnectionPool {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
port: 25,
host: 'localhost',
options: [Object],
_connectionsAvailable: [],
_connectionsInUse: [Object],
_messageQueue: [Object],
_idgen: 2 } },
version: '0.3.35',
sendMail: [Function] }
As you can clearly see it is using different setting then defined by me. 你可以清楚地看到它使用了我定义的不同设置。
I am unable to find the issue. 我无法找到问题。 Any help will be appreciated.
任何帮助将不胜感激。
if you want to send mail through aws it is better to use aws-sdk
module. 如果你想通过aws发送邮件,最好使用
aws-sdk
模块。 usage is given below 用法如下
var aws = require('aws-sdk');
module.exports = function (to, from, sub, body) {
aws.config.update({
accessKeyId: 'accessKeyId',
secretAccessKey: 'secretAccessKey',
region: 'region'
});
// load AWS SES
var ses = new aws.SES({apiVersion: 'latest'});
// this sends the email
ses.sendEmail({
Source: from,
Destination: {
ToAddresses: to
},
Message: {
Subject: {
Data: sub
},
Body: {
Html: {
Data: body
}
}
}
}
, function (err, data) {
if (err) {
console.log(err);
} else {
console.log('Email sent:');
console.log(data);
}
});
};
Hope it helps :) 希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.