【问题标题】:AWS SES send email not workingAWS SES 发送电子邮件不起作用
【发布时间】:2016-12-25 10:26:59
【问题描述】:

实际上,我是使用 AmazonWebService(AWS) 的新手,但就我而言,我必须使用 node.js 创建一些程序来使用 AWS SES node.js 发送电子邮件

我已阅读所有 AWS SES 文档,但我不太明白。一些博客写了教程,我遵循了他们的代码,但在我的代码中它不起作用。

我有两个编写的示例代码。这里是第一个代码:

var nodemailer = require('nodemailer');
var ses = require('nodemailer-ses-transport');

var transporter = nodemailer.createTransport(ses({
    accessKeyId: 'xxxxxxxxxxxxxxxxxxx',
    secretAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxx'
}));

transporter.sendMail({
    from: 'avi.adhi@vasww.com',
    to: 'gengar@gmail.com',
    subject: 'My Amazon SES Simple Email',
    text: 'Amazon SES is cool'
});

以上是来自http://budiirawan.com/send-emails-using-amazon-ses-and-node-js/的代码参考

第二个是这样的:

var aws = require('aws-sdk');

var ses = new aws.SES({
   accessKeyId: 'xxxxxxxxxxxxxxxxxxx',
   secretAccesskey: 'xxxxxxxxxxxxxxxxxxxxxxxx',
   region: 'us-west-2' 
});

// send to list
var to = ['gengar@gmail.com'];

// this must relate to a verified SES account
var from = 'avi.adhi@vasww.com';


// this sends the email
// @todo - add HTML version
ses.sendEmail( { 
   Source: from, 
   Destination: { ToAddresses: to },
   Message: {
        Subject: {
            Data: 'A Message To You'
        },
       Body: {
           Text: {
               Data: 'Stop your messing around',
           }
        }
   }
}
, function(err, data) {
    if(err) throw err
        console.log('Email sent:');
        console.log(data);
 });

来自http://timstermatic.github.io/blog/2013/08/14/sending-emails-with-node-dot-js-and-amazon-ses/ 的第二个代码引用。 第二个代码给我错误信息:

C:\xampp\htdocs\mail\node_modules\aws-sdk\lib\request.js:31
            throw err;
            ^
Error: connect ENETUNREACH :80
    at Object.exports._errnoException (util.js:856:11)
    at exports._exceptionWithHostPort (util.js:879:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)

两者都不起作用,我已确保我的 AWS 访问密钥正确,并且我的 avi.adhi@avasww.com 已通过 AWS SES 验证。如果有人可以解决这个问题,我非常感谢。

【问题讨论】:

    标签: node.js amazon-web-services


    【解决方案1】:

    我已经找到了解决此案的方法。第一个代码确实有效,我只是忘记在 SES 声明中包含 AWS 区域,我们应该从 AWS 收到经过验证的电子邮件。这是我的新代码,它运行良好。谢谢

    var nodemailer = require('nodemailer');
    var ses = require('nodemailer-ses-transport');
    
    var transporter = nodemailer.createTransport(ses({
        accessKeyId: 'xxxxxxxxxxxxxxxxxxx',
        secretAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        region: 'us-west-2' 
    }));
    
    transporter.sendMail({
        from: 'your_verified_email@xxxx.com',
        to: 'target_email@xxxx.com',
        subject: 'Email Testing',
        html: '<h1>Title</h1>',
        attachments: [
            {
              filename: 'report',
              path: 'C:\\xampp\\htdocs\\js\\report.xlsx',
              contentType: 'application/vnd.ms-excel'
            }
        ]
    }
    , function(err, data) {
        if(err) throw err
            console.log('Email sent:');
            console.log(data);
     });
    

    该代码也使用发送附件,希望对遇到相同情况的人有所帮助。

    【讨论】:

      【解决方案2】:

      错误Error: connect ENETUNREACH :80 表示网络不可达。这是某种网络问题,可能是安全组问题。

      你能telnet出站到邮件服务器并确认吗?

      更改安全组设置以允许所有出站流量,然后重试。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-07
        • 2020-10-20
        • 2017-11-11
        • 1970-01-01
        • 2022-05-23
        • 2019-03-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多