amazon-web-services - 来自带有 Debian 后缀的 EC2 实例的 Amazon SES 中继无法发送电子邮件

标签 amazon-web-services debian amazon-ses

我被要求做一些系统管理员,并将遗留的 PHP Web 应用程序移动到运行 Debian 的 Amazon EC2 实例。我已完成此操作,并且已成功从 postfix 发送电子邮件。

之前的系统管理员表示担心服务器没有使用电子邮件中继,而使用 SES 的请求似乎很简单。我已经使用 Rackspace 实例中的 Mailgun 实现了邮件中继,尽管这并不简单,但我在几个小时内就完成了。

我没有发现 SES 过程如此简单,我怀疑这是因为我不熟悉使用证书。

最初我使用此处的说明设置服务 http://docs.aws.amazon.com/ses/latest/DeveloperGuide/postfix.html

  • 为服务器设置弹性IP
  • 为 SMTP 服务器创建的凭据
  • 创建了 IAM 用户并获得了用于 SMTP 的用户名和密码 电子邮件-smtp.us-west-2.amazonaws.com
  • 我创建了一个/etc/postfix/sasl_passwd 文件

[email-smtp.us-west-2.amazonaws.com]:25 USERNAME:PASSWORD

  • 然后我跑了

    postmap hash:/etc/postfix/sasl_passwd

创建 sasl_passwd.db

  • /etc/postfix/master.cf 中没有 smtp_fallback_relay

  • 我通过安装 apt-get install sasl2-bin 创建了一个证书

    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt

并在我的 main.cf 中将后缀指向此(在本文末尾)。

我正在使用 sendmail 通过 Python 发送电子邮件

SENDMAIL = "/usr/sbin/sendmail" # sendmail location

FROM = "andy@travelinsurancequotes.com.au"
#TO = ["kirstie@travelinsurancequotes.com.au", "jason@slatescience.com"]
TO = ["jason@slatescience.com"]

SUBJECT = "Artog SMTP server is working!"

TEXT = "Sending emails on the TIQ webserver is working"

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

import os

p = os.popen("%s -f %s -t -i" % (SENDMAIL, FROM), "w")
p.write(message)
status = p.close()
if status:
    print "Sendmail exit status", stat

但我在发送时一直收到超时错误:

Feb 26 03:18:19 lamp postfix/error[23414]: 5DE3240508: to=<jason@slatescience.com>, relay=none, delay=0.02, delays=0.02/0/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to email-smtp.us-west-2.amazonaws.com[54.187.123.10]:25: Connection timed out

我可以通过端口 25 连接

root@lamp /home/www# telnet email-smtp.us-west-2.amazonaws.com 25
Trying 54.149.142.243...
Connected to ses-smtp-us-west-2-prod-14896026.us-west-2.elb.amazonaws.com.
Escape character is '^]'.
220 email-smtp.amazonaws.com ESMTP

我的main.cf文件是

myhostname              = travelinsurancequotes.com.au
mydomain                = travelinsurancequotes.com.au
inet_interfaces = all

mynetworks_style        = host
local_destination_recipient_limit       = 300
local_destination_concurrency_limit     = 5
recipient_delimiter=+

smtpd_banner            = $myhostname

smtpd_sasl_auth_enable          = yes
smtp_sasl_mechanism_filter = plain
smtpd_sasl_local_domain         = $myhostname
broken_sasl_auth_clients        = yes
smtpd_helo_required             = yes
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/sslcerts/server.key
smtpd_tls_cert_file = /etc/postfix/sslcerts/server.crt
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

relayhost = [email-smtp.us-west-2.amazonaws.com]:25
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

最佳答案

AWS EC2 对发送的邮件有某种限制..

我遇到了那个错误,Amazon 支持告诉我填写此表格以取消限制。

https://aws.amazon.com/forms/ec2-email-limit-rdns-request

希望对你有帮助

关于amazon-web-services - 来自带有 Debian 后缀的 EC2 实例的 Amazon SES 中继无法发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35643010/

相关文章:

java - Amazon SES - 使用 IAM 角色发送电子邮件

node.js - 类型错误 : Key must be a buffer when sending an email with aws-sdk in node. js

linux - 使用 "aws s3"实用程序在 S3 中获取从现在起 1 个月前的文件列表

linux - 在 debian wheezy 上安装 gstreamer1.0(依赖项 libgstreamer-plugins-base1.0-0 和 liborc-0.4-0)

linux - 如何杀死僵尸进程

php - 退出前触发函数

azure - 使用 Azure Functions 通过 Amazon SES 发送电子邮件

amazon-web-services - 通过堡垒主机将 ssh 端口转发到 VPC 中的 Elasticsearch 集群无法正常工作

javascript - AWS 无服务器端点问题

amazon-web-services - 使用 Terraform 部署 CloudFormation 模板