后缀发送延迟的电子邮件

我在Amazon Lightsail上运行Ubuntu 16.04。 我只是configurationPostfix发送电子邮件

  • 如果我在几个小时后发送电子邮件,则会立即收到电子邮件。

  • 如果我在一封电子邮件中发送多封电子邮件,则会延迟10-30分钟。

问题:

  1. 如何解决延迟问题,以便即时发送电子邮件?
  2. 如何确保通过本地应用程序发送给用户(root&ubuntu)的所有电子邮件都被发送到具有相同域的外部电子邮件?

我的configuration:

在/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.xxx search ec2.internal 

/ etc / hosts文件

 127.0.0.1 localhost 127.0.1.1 webserver.DOMAIN-NAME.com webserver 3x.xxx webserver.DOMAIN-NAME.com webserver #3.xxx 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 / aliases中

 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 

亚马逊Lightsail是面向networking应用程序开发人员的低端低价云VPS解决scheme。 Lightsail文档中的所有内容都与select和configurationWeb服务器和CMS平台有关。 它没有明确说明,但另外显而易见的是,Lightsail并不是一个电子邮件服务器。 即使你的服务器的名字是webserver

Web应用程序可能每隔一段时间发送一次电子邮件。 因此SMTP端口25没有被完全阻塞,而是有局限性。 您的Postfixconfiguration适用于独立的SMTP服务器,但是mail.log显示了正在发生的事情:达到限制后,SMTP连接会超时,邮件被deferred ,推迟以供以后尝试使用。 基于RFC 3463的SMTP状态码 dsn=4.4.1说的:

4.4.1 收件人的服务器没有响应

这是从您的服务器发出的错误,指示收件人的服务器没有响应。 您的服务器将自动尝试多次 – 有多less取决于您的服务器configuration。

您在评论中提到,这只会发生在Ubuntu上的Postfix上,而不是在Amazon Linux上的Sendmail上。 我对亚马逊Linux和亚马逊SES并不是很熟悉,但我猜亚马逊Linux Sendmail可能会将亚马逊SES预configuration为中继。 也可以将Amazon SES与Postfix集成在一起 。

因为您有relayhost = $mydomain ,您可能正试图将所有邮件转发到您的域的外部邮件服务器,因为它应该是。 但是,对于您的外部MTA,端口25的限制没有例外。 因此,您应该使用消息提交代理 (端口587

  1. 您必须在您的电子邮件服务器中configurationMSA。 如果它也是Postfix,你应该有/etc/postfix/master.cf部分以submission /etc/postfix/master.cf开头:

     submission inet n - - - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING 
  2. configuration您的Lightsail relayhost使用提交端口和authentication, main.cf

     relayhost = $mydomain:587 # Alternative example without DNS MX lookup: # relayhost = [mail.example.com]:587 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 
  3. /etc/postfix/sasl_passwd是Berkeley DB ( hash: /etc/postfix/sasl_passwd用于用户名和密码信息用于与邮件网关服务器进行身份validation。 例子:

     # destination credentials [mail.example.com] username:password # Alternative form: # [mail.example.com]:submission username:password 

有关更多详细信息,请参阅Postfix SASL Howto 。