解决阿里云 ECS 用 php sendmail 发送邮件极为缓慢的问题
今天用 Contact Form 7 给悠悦俄语网添加用户反馈功能,突然发现服务器发送邮件要很久很久。
于是先看一下邮件发送日志:
vi /var/log/maillog
Apr 3 18:18:34 iZ2ze7ykmwwdhkhece01gbZ sendmail[941]: My unqualified host name (iZ2ze7ykmwwdhkhece01gbZ) unknown; sleeping for retry
Apr 3 18:19:34 iZ2ze7ykmwwdhkhece01gbZ sendmail[941]: unable to qualify my own domain name (iZ2ze7ykmwwdhkhece01gbZ) -- using short name
Apr 3 18:19:34 iZ2ze7ykmwwdhkhece01gbZ sendmail[1277]: starting daemon (8.14.7): SMTP+queueing@01:00:00
Apr 3 18:19:34 iZ2ze7ykmwwdhkhece01gbZ sm-msp-queue[1289]: My unqualified host name (iZ2ze7ykmwwdhkhece01gbZ) unknown; sleeping for retry
Apr 3 18:20:34 iZ2ze7ykmwwdhkhece01gbZ sm-msp-queue[1289]: unable to qualify my own domain name (iZ2ze7ykmwwdhkhece01gbZ) -- using short name
太吓人了,找不到主机名,于是睡眠等待,一分钟一次,等了两分钟才使用短名称。吓得我赶紧看看 hosts:
vi /etc/hosts
127.0.0.1 localhost
::1 localhost.localdomain localhost6 localhost6.localdomain6
10.27.241.233 iZ2ze7ykmwwdhkhece01gbZ
不敢相信这是阿里云 ECS 的默认配置,如果有高人认为这样没问题,麻烦跟我讲解一下。我还是先改了它吧。
hostnamectl set-hostname iZ2ze7ykmwwdhkhece01gbZ
vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.27.241.233 iZ2ze7ykmwwdhkhece01gbZ.localdomain iZ2ze7ykmwwdhkhece01gbZ
iZ2ze7ykmwwdhkhece01gbZ 可以改为任意名称,不过,最好不是 localhost,否则,需要把 localhost.localdomain 移到 localhost 之前。改完之后再次测试发邮件,一秒内成功。
注意:专有网络下,即使这样设置也无法发送邮件,因为不开放25端口。可以通过TLS(端口587)或者SSL(端口465)加密方式发送邮件。