简体   繁体   English

来自EC2实例的Amazon SES中继和Debian上的postfix无法发送电子邮件

[英]Amazon SES relay from EC2 instance with postfix on Debian can't send email

I have been asked to do some system admin and to move a legacy PHP web application to an Amazon EC2 instance running Debian. 我被要求做一些系统管理员并将遗留的PHP Web应用程序移动到运行Debian的Amazon EC2实例。 I have done this, and emails are successfully being sent from postfix. 我已经这样做了,并且成功地从postfix发送了电子邮件。

Concern was expressed by the previous system admin that the server was not using an email relay, and a request to use SES seemed straight forward. 先前的系统管理员表示担心服务器没有使用电子邮件中继,并且使用SES的请求似乎很简单。 I have implemented a mail relay using Mailgun from a Rackspace instance, and though not trivial, I got this done in a couple of hours. 我已经从Rackspace实例使用Mailgun实现了一个邮件中继,虽然不是很简单,但我在几个小时内完成了这项工作。

I have not found the SES process quite so simple, and I suspect this is because I am unfamiliar with using certificates. 我没有发现SES过程非常简单,我怀疑这是因为我不熟悉使用证书。

Initially I set up the service using the instructions here http://docs.aws.amazon.com/ses/latest/DeveloperGuide/postfix.html 最初我使用http://docs.aws.amazon.com/ses/latest/DeveloperGuide/postfix.html中的说明设置服务。

  • Elastic IP set up for server 为服务器设置弹性IP
  • Credentials created for SMTP server 为SMTP服务器创建的凭据
  • Created IAM user and got a username and password for SMTP at email-smtp.us-west-2.amazonaws.com 创建了IAM用户,并在email-smtp.us-west-2.amazonaws.com上获得了SMTP的用户名和密码
  • I created an /etc/postfix/sasl_passwd file with 我创建了一个/ etc / postfix / sasl_passwd文件

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

  • I then ran 然后我跑了

    postmap hash:/etc/postfix/sasl_passwd postmap hash:/ etc / postfix / sasl_passwd

to create the sasl_passwd.db 创建sasl_passwd.db

  • /etc/postfix/master.cf did not have smtp_fallback_relay in it /etc/postfix/master.cf中没有smtp_fallback_relay

  • I created a certificate by installing apt-get install sasl2-bin and 我通过安装apt-get install sasl2-bin和创建了一个证书

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

and pointing postfix to this in my main.cf (at the end of this post). 并在我的main.cf中指向postfix(在本文末尾)。

I am using sendmail to send an email via Python 我使用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

but I keep getting a time out error on sending: 但我在发送时不断出错:

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

I can connect via port 25 我可以通过端口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

My main.cf file is 我的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 has some sort of limit on mail being sent .. AWS EC2对发送的邮件有某种限制。

I had that error, and Amazon Support told me to fill this form out to remove the limit. 我有这个错误,亚马逊支持部门告诉我填写此表格以取消限制。

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

I hope this helps 我希望这有帮助

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM