【问题标题】:Amazon SES relay from EC2 instance with postfix on Debian can't send email来自 Debian 上带有后缀的 EC2 实例的 Amazon SES 中继无法发送电子邮件
【发布时间】:2016-06-09 03:42:39
【问题描述】:

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

之前的系统管理员表示担心服务器没有使用电子邮件中继,使用 SES 的请求似乎很直接。我已经使用 Rackspace 实例中的 Mailgun 实现了一个邮件中继,虽然这不是微不足道的,但我在几个小时内就完成了。

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

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

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

[email-smtp.us-west-2.amazonaws.com]:25 用户名:密码

  • 然后我跑了

    postmap 哈希:/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

【问题讨论】:

    标签: amazon-web-services debian amazon-ses


    【解决方案1】:

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

    我遇到了这个错误,亚马逊支持让我填写此表格以取消限制。

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

    希望对你有帮助

    【讨论】:

    • 谢谢。不幸的是,我无法尝试您的解决方案,因为我不再拥有访问权限。不过,亚马逊支持应该告诉我这一点。这种限制对很多人来说肯定是个问题,Rackspace 不是问题(虽然他们有其他问题,但他们的支持很好)。与亚马逊合作的决定是教条。
    • 其实我同意。我花了一些时间试图弄清楚。很惊讶任何托管公司都会限制虚拟机的 25 端口。我仍在努力设置 rDNS,现在它报告为我的 EC2 内部 IP。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-06-04
    • 2012-06-22
    • 2016-08-22
    相关资源
    最近更新 更多