简体   繁体   English

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

[英]Node.Js AWS SES - ETIMEDOUT when sending Email

I want to send a verification Email to new people signing up via AWS SES in Node.js: 我想向通过Node.js中的AWS SES注册的新人发送验证电子邮件:

var params = {
    Destination: {
        ToAddresses: [
            '...',
        ]
    },
    Message: {
        Body: {
            Html: {
                Data: '...',
                Charset: 'utf-8'
            },
            Text: {
                Data: '...',
                Charset: 'utf-8'
            }
        },
        Subject: {
            Data: '...',
            Charset: 'utf-8'
        }
    },
    Source: '...',
    ReturnPath: '...',
};
const ses = new AWS.SES({
    my_accessKeyId,
    my_secretAccessKey,
    my_region,
})
ses.sendEmail(params, function (err, data) {
    // ...
});

Unfortunately, nothing happens and after a minute or so I get the following error: 不幸的是,什么也没有发生,大约一分钟后,我收到以下错误消息:

{ Error: connect ETIMEDOUT 35.157.44.176:443
    at Object._errnoException (util.js:992:11)
    at _exceptionWithHostPort (util.js:1014:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
  message: 'connect ETIMEDOUT 35.157.44.176:443',
  code: 'NetworkingError',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '35.157.44.176',
  port: 443,
  region: 'eu-central-1',
  hostname: 'email.eu-central-1.amazonaws.com',
  retryable: true,
  time: 2018-10-18T16:52:00.803Z }

I am not sure if the error results from a mistake in my code, as I am currently only using the sandbox environment. 我不确定错误是否是由于我的代码中的错误导致的,因为我目前仅使用沙盒环境。 But I verified the sending and receiving email, which should work fine even in sandbox mode. 但是我验证了发送和接收电子邮件,即使在沙盒模式下也可以正常工作。


PS I am not quite sure how to properly test my application when being in sandbox mode, as I am not allowed to send to unverified emails. PS:我不确定在沙盒模式下如何正确测试我的应用程序,因为不允许发送未经验证的电子邮件。 Is it possible to request production access without a proper application running? 如果没有运行适当的应用程序,是否可以请求生产访问权限?

It's not obvious, so we'll need to do some troubleshooting. 这并不明显,因此我们需要进行一些故障排除。

First, lets see if you can connect from your local machine to the SES API using the AWS CLI. 首先,让我们看看是否可以使用AWS CLI从本地计算机连接到SES API。 Make sure you have set up the aws credentials using aws configure and try: 确保使用aws configure设置了aws凭证,然后尝试:

aws ses list-identities

If this works, you should see a list of validated email addresses. 如果可行,您应该会看到经过验证的电子邮件地址列表。 If not, you will see an error (permissions maybe), or a timeout suggests a network connectivity issue. 如果没有,您将看到一个错误(可能是权限),或者超时提示网络连接问题。

Note on credentials: Don't include your credentials in your code, either configure a .credentials file , which happens when you used the aws configure above, load it from a shared json file or use environment variables (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY). 关于凭证的注意事项:不要在代码中包含凭证,请配置.credentials文件 (当您使用上面的aws configure时发生), 从共享的json文件加载它,或者使用环境变量(AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY)。

Next, try to do the same in code: 接下来,尝试在代码中执行相同的操作:

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region 
AWS.config.update({region: 'eu-central-1'});
// Create SES Client
const ses = new AWS.SES({apiVersion: '2010-12-01'})
// Create params
var params = {
  IdentityType: "EmailAddress", 
  MaxItems: 123, 
  NextToken: ""
};
ses.listIdentities(params, function(err, data) {
   if (err) console.log(err, err.stack); // an error occurred
   else     console.log(data);           // successful response
});

After you set up your credentials as mentioned above, use this in your Send Email code to create the ses client: 如上所述设置凭据后,请在“发送电子邮件”代码中使用此凭据创建ses客户端:

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region 
AWS.config.update({region: myregion});
// Create SES Client
const ses = new AWS.SES({apiVersion: '2010-12-01'})

Other things to check: 其他要检查的内容:

  • Make sure that all the email addresses are verified ("From", "Source", "Sender", or "Return-Path") 确保所有电子邮件地址均已验证 (“发件人”,“源”,“发件人”或“返回路径”)
  • Make sure that you have the correct SES Access Keys 确保您具有正确的SES访问密钥
  • If using EC2, make sure that the security groups allow access to the AWS API. 如果使用EC2,请确保安全组允许访问AWS API。
  • I hope it's working by now, if not I can only say go to this page and make sure you haven't missed anything obvious. 我希望它现在能正常运行,如果不能,我只能说转到本页并确保您没有错过任何明显的内容。

You need to change region from eu-central-1 to region where endpoint exist (eg. eu-west-1) in order to send emails out 您需要将区域从eu-central-1更改为端点存在的区域(例如eu-west-1),以便发送电子邮件

https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html

You need to make sure your user your using to send the email 您需要确保您的用户用来发送电子邮件

my_accessKeyId,
    my_secretAccessKey,

has the correct IAM permissions (role attached to it) to send the email with ses. 具有正确的IAM权限(已附加角色)以发送带有ses的电子邮件。 Test with the role SES full access I believe. 我相信,请对角色SES进行完全访问进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用SES node.js发送电子邮件 - Sending email using SES node.js node.js上的SES虽然返回“成功”响应,但没有发送电子邮件 - SES on node.js not sending the email although it return 'success' response 通过 aws ses 在 node.js 中发送带有附件的邮件 - Sending mail via aws ses with attachment in node.js 使用Node.js处理程序发送和发送电子邮件时出现AWS Lambda NetworkingError - AWS Lambda NetworkingError when sending and email with a Node.js handler 使用 Node.js 中的 AWS SES 在 email 正文中发送超链接 - Send hyperlinks in email body using AWS SES in Node.js AWS SES 计划发送电子邮件(节点 SDK) - AWS SES Schedule sending of email (Node SDK) 在RDS中访问MySQL或MS SQL时的AWS Lambda node.js ETIMEDOUT - AWS Lambda node.js ETIMEDOUT when accessing MySQL or MS SQL in RDS 无法通过在 EC2 实例上运行的 Node.js 应用程序使用 AWS SES 发送 email - Cannot send email using AWS SES via Node.js app running on EC2 instance 从AWS Lambda发送SES电子邮件-节点JS错误“找不到模块'nodemailer” - Sending SES email from AWS Lambda - Node JS Error “Cannot find module 'nodemailer” TypeError:在node.js中使用aws-sdk发送电子邮件时,密钥必须是缓冲区 - TypeError: Key must be a buffer when sending an email with aws-sdk in node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM