我在 Amazon Lightsail 上运行 Ubuntu 16.04。我只是将 Postfix 配置为发送电子邮件。
如果我在几个小时后发送电子邮件,则会立即收到电子邮件。
如果我同时发送多封电子邮件,电子邮件会延迟大约 10-30 分钟。
问题:
- 如何修复延迟以便立即发送电子邮件?
- 如何确保本地应用程序发送给用户(root 和 ubuntu)的所有电子邮件都发送到具有相同域的外发电子邮件?
我的配置:
/etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 172.x.x.x
search ec2.internal
/etc/hosts
127.0.0.1 localhost
127.0.1.1 webserver.DOMAIN-NAME.com webserver
3x.x.x.x webserver.DOMAIN-NAME.com webserver #3.x.x.x is the IP that is mentioned in domain DNS
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
/etc/主机名
webserver
/etc/别名
postmaster: root
root: [email protected]
/etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
# Debian specific: Specifying a file name will cause the first
# line of that file to be used as the name. The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h
readme_directory = no
# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = webserver.DOMAIN-NAME.com
mydomain = DOMAIN-NAME.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#myorigin = /etc/mailname
myorigin = $mydomain
#mydestination = $myhostname, DOMAIN-NAME.com, webserver.DOMAIN-NAME.com, localhost.DOMAIN-NAME.com, localhost
mydestination =
#relayhost =
relayhost = $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
#inet_interfaces = all
inet_interfaces = loopback-only
#inet_protocols = all
inet_protocols = ipv4
/var/log/mail.log
May 1 02:17:15 webserver postfix/smtp[6105]: 0287CC775F: to=<[email protected]>, relay=alt1.aspmx.l.google.com[64.233.190.27]:25, delay=531, delays=465/0.01/64/1.9, dsn=2.0.0, status=sent (250 2.0.0 OK 1493605035 h2si13051738qte.100 - gsmtp)
May 1 02:17:15 webserver postfix/qmgr[6102]: 0287CC775F: removed
May 1 02:17:40 webserver postfix/smtp[6107]: connect to alt1.aspmx.l.google.com[64.233.190.27]:25: Connection timed out
May 1 02:17:40 webserver postfix/smtp[6108]: connect to alt1.aspmx.l.google.com[64.233.190.27]:25: Connection timed out
May 1 02:18:10 webserver postfix/smtp[6108]: connect to aspmx2.googlemail.com[64.233.190.27]:25: Connection timed out
May 1 02:18:10 webserver postfix/smtp[6107]: connect to aspmx3.googlemail.com[209.85.203.26]:25: Connection timed out
May 1 02:18:40 webserver postfix/smtp[6108]: connect to aspmx3.googlemail.com[209.85.203.26]:25: Connection timed out
May 1 02:18:40 webserver postfix/smtp[6107]: connect to aspmx2.googlemail.com[64.233.190.27]:25: Connection timed out
May 1 02:18:40 webserver postfix/smtp[6108]: CBE50C77C6: to=<[email protected]>, relay=none, delay=7845, delays=7695/0.02/150/0, dsn=4.4.1, status=deferred (connect to aspmx3.googlemail.com[209.85.203.26]:25: Connection timed out)
May 1 02:18:40 webserver postfix/smtp[6107]: 2266DC775D: to=<[email protected]>, relay=none, delay=174, delays=24/0.01/150/0, dsn=4.4.1, status=deferred (connect to aspmx2.googlemail.com[64.233.190.27]:25: Connection timed out)
May 1 02:20:02 webserver postfix/scache[6110]: statistics: start interval May 1 02:16:41
May 1 02:20:02 webserver postfix/scache[6110]: statistics: domain lookup hits=0 miss=1 success=0%
May 1 02:20:02 webserver postfix/scache[6110]: statistics: address lookup hits=0 miss=2 success=0%
May 1 02:20:02 webserver postfix/scache[6110]: statistics: max simultaneous domains=1 addresses=1 connection=1
May 1 02:26:10 webserver postfix/qmgr[6102]: 2266DC775D: from=<[email protected]>, size=425, nrcpt=1 (queue active)
May 1 02:26:10 webserver postfix/smtp[6138]: 2266DC775D: to=<[email protected]>, relay=aspmx.l.google.com[209.85.201.26]:25, delay=625, delays=624/0.01/0.09/0.18, dsn=2.0.0, status=sent (250 2.0.0 OK 1493605570 p15si12740899qta.122 - gsmtp)
May 1 02:26:10 webserver postfix/qmgr[6102]: 2266DC775D: removed
Amazon Lightsail 是面向 Web 应用程序开发人员的低端低价云 VPS 解决方案。Lightsail 文档中的所有内容都与选择和配置 Web 服务器和 CMS 平台有关。没有明确说明,但很明显 Lightsail 不适合作为电子邮件服务器。甚至您的服务器的名称也是
webserver
!Web 应用程序可能会每隔一段时间发送一封电子邮件。因此 SMTP 端口 25 并没有被完全封锁,而是有一些限制。您的 Postfix 配置对于独立的 SMTP 服务器来说是可以的,但
mail.log
显示了正在发生的事情:达到限制后,SMTP 连接超时并且邮件获取deferred
,推迟到稍后尝试。基于RFC 3463的SMTP 状态代码dsn=4.4.1
说明相同:您在评论中提到,这只发生在 Ubuntu 上的 Postfix 上,而不是 Amazon Linux 上的 Sendmail 上。我对 Amazon Linux 和 Amazon SES不太熟悉,但我猜 Amazon Linux Sendmail 可能会将 Amazon SES 预配置为中继。也可以将 Amazon SES 与 Postfix 集成。
正如您所拥有的那样
relayhost = $mydomain
,您可能正在尝试将所有邮件中继到您域的外部邮件服务器,因为它应该是。但是,端口限制25
对于您的外部 MTA 也不例外。因此,您应该改用消息提交代理(端口587
)。您必须在电子邮件服务器中配置 MSA。如果它也是 Postfix,你应该有以未注释
/etc/postfix/master.cf
开头的部分:submission
配置您的 Lightsail
relayhost
以使用提交端口和身份验证,main.cf
:这
/etc/postfix/sasl_passwd
是用于与邮件网关服务器进行身份验证的用户名和密码信息的Berkeley DB (hash:
)。例子:有关更多详细信息,请参阅Postfix SASL Howto。