Nodemailer无法使用生产服务器上的aws发送邮件

时间:2016-03-16 10:56:22

标签: node.js amazon-web-services nodemailer

我在通过nodemailer和AWS发送邮件时遇到了问题。以下是我的设置:

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'
    }
}));

邮件发送代码:

    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);
         }
 });

我收到以下错误:

{ [Error: connect ECONNREFUSED 127.0.0.1:25]
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 25,
  stage: 'init' }

这是我打印时我的运输车对象的样子:

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] }

您可以清楚地看到它使用了我定义的不同设置。

我无法找到问题。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:3)

如果你想通过aws发送邮件,最好使用var view= list.get_views().getByTitle("YourView"); view.set_scope(2);模块。用法如下:

aws-sdk

希望有所帮助:)