AWS SES发送电子邮件不起作用

愤怒

实际上,我是使用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: '[email protected]',
    to: '[email protected]',
    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 = ['[email protected]'];

// this must relate to a verified SES account
var from = '[email protected]';


// 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访问密钥正确并且AWS SES已验证我的[email protected]如果有人可以解决这个问题,我非常感激。

愤怒

我已经找到了解决这种情况的方法。第一个代码实际上有效,我只是忘了将AWS Region包含在SES声明中,我们应该从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: '[email protected]',
    to: '[email protected]',
    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);
 });

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

JavaScript-使用AWS SES发送电子邮件

气流-使用AWS SES发送电子邮件

AWS Lambda 无法通过 AWS SES 发送电子邮件

在AWS Lambda函数中通过AWS SES发送电子邮件

我可以使用域名下的任何电子邮件通过AWS SES发送电子邮件吗?

发送电子邮件时,如何为Amazon SES服务提供AWS密钥?

使用 aws ses sdk(Java) 从亚太地区(孟买)发送电子邮件

发送电子邮件时,Node.Js AWS SES-ETIMEDOUT

无法使用Amazon AWS,SES和PostFix发送电子邮件

AWS SES不使用SendRawEmail操作发送电子邮件

通过AWS SES发送电子邮件时的Openssl问题

通过AWS SES批量发送电子邮件,有什么想法吗?

Amazon AWS:通过SES发送电子邮件的速度超慢

如何通过AWS SES向多个收件人发送电子邮件

使用Laravel Mail类通过AWS SES发送电子邮件

通过 AWS SES 发送电子邮件是否仍取决于电子邮件托管的每日电子邮件数量限制?

尝试使用Alexa和AWS SES发送电子邮件。电子邮件将发送,但是Alexa将返回并且错误

代表用户从GCE或AWS发送电子邮件

从 Python 脚本通过 AWS Workmail 发送电子邮件

从AWS Lambda函数发送电子邮件

Amazon AWS发送电子邮件形式RoR

使用来自 AWS 的 SES 发送电子邮件时出现“连接意外关闭”错误

从没有弹性IP的EC2发送电子邮件到AWS SES

Android:亚马逊AWS SES不会在某些中国手机上发送电子邮件

1m后脚本损坏,状态失败,使用AWS SES发送电子邮件时PHP-Apache

使用Amazon SES服务从node.js发送电子邮件不起作用

AWS SES SDK发送带有附件的电子邮件

从php发送电子邮件不起作用

在 aspnetboilerplate 中发送电子邮件不起作用