VPS上默认安装了sendmail,php也启用了mail函数,OpenCart后台的Mail 设置中选择Mail
而不是SMTP后,发送邮件到Gmail失败。查看日志记录:
vi /var/spool/mail/root
—– Transcript of session follows —–
… while talking to gmail-smtp-in.l.google.com.:
>>> DATA
<<< 550-5.7.1 [xxxxxx 1] Our system has detected an
unusual rate of
<<< 550-5.7.1 unsolicited mail originating from your IP
address. To protect our
<<< 550-5.7.1 users from spam, mail sent from your IP
address has been blocked.
<<< 550-5.7.1 Please visit
http://www.google.com/mail/help/bulk_mail.html to review
<<< 550 5.7.1 our Bulk Email Senders Guidelines.
u2si18399648wia.22
554 5.0.0 Service unavailable
再看google提供的网址说明
Use a consistent IP address1 to send bulk mail.
Keep valid reverse DNS records for the IP address(es) from
which you send mail, pointing to your domain.
Use the same address in the ‘From:’ header on every bulk mail
you send.
eukhost:Reverse DNS can set to any domain pointing to the
ipaddress & it is not necessary that reverse DNS should be
pointed to the hostname only. AOL may have rejected the mail
because there was no reverse DNs set。
再测试发送到163邮箱:
—– Transcript of session follows —–
… while talking to 163mx02.mxmail.netease.com.:
>>> MAIL From:<apache@VPSin> BODY=8BITMIME
<<< 550 MI:IMF mx22,SMCowEDZQUaPd4FQVFQICw–.12227S2
1350662033
http://mail.163.com/help/help_spam_16.htm?ip=xxxxxxxxxx&hostid=mx22&time=1350662033
554 5.0.0 Service unavailable
550 MI:IMF 发信人电子邮件地址不合规范。
用命令 host ip.address 或者traceroot 发现确实没有rDNS设置。
这家vps后台直接设置rDNS貌似不行,记得Linode vps 是可以自己直接设置的。而burst.net据网友说可以发ticket帮忙设置,所以发ticket给support,给设置相应的reverse
DNS (有的地方说法是PTR/SPF txt 记录)。设置好后,发现opencart
发送邮件是没问题了,但是发送邮件速度很慢。
这时可以暂时先用SMTP来发送邮件。
使用SMTP,比如Google app: http://www.google.com/a
Mail Protocol: SMTP
Mail Parameters: 无则留空
SMTP Host:ssl://smtp.gmail.com
SMTP Username: xxx@xxx.com
SMTP Password: xxx
SMTP Port: 465
SMTP Timeout: 10
注意google 提供的SMTP Host
前面要加上ssl://,记得Discuz中的email设置也是一样。不然发送邮件会失败。但是免费的Gmail
邮箱的smtp服务据说是有每天发送量限制的,每天超过100个收件人就会被暂停24小时。
最后还是来看下sendmail 发送邮件慢的问题,
发送一封测试邮件:
/usr/sbin/sendmail -t <<EOF
From: Mail testing <fdsfds@gmail.com>
To: myhotmail@hotmail.com
Subject: mail fodkdd
———————————-
这是一封测试邮件。
———————————
EOF
再看日志文件 vi /var/log/maillog:
Nov 19 01:36:26 VPS98889on sendmail[21021]: My unqualified
host name (VPS98889on) unknown; sleeping for retry
Nov 19 01:37:26 VPS98889on sendmail[21021]: unable to qualify
my own domain name (VPS98889on) — using short name
Nov 19 01:37:27 VPS98889on sendmail[21021]: qAJ7bQwu021021:
from=root, size=208,, nrcpts=1,
msgid=<201211190737.qAJ7bQwu021021@VPS98889on>,
relay=root@localhost
Nov 19 01:37:33 VPS98889on sendmail[21022]: qAJ7bRtP021022:
from=<root@VPS98889on>, size=420,, nrcpts=1,
msgid=<201211190737.qAJ7bQwu021021@VPS98889on>, proto=ESMTP,
daemon=MTA, relay=localhost [127.0.0.1]
Nov 19 01:37:35 VPS98889on sendmail[21021]: qAJ7bQwu021021:
to=myhotmail@hotmail.com, ctladdr=root (0/0), delay=00:00:09,
xdelay=00:00:08, mailer=relay, pri=30208, relay=[127.0.0.1]
[127.0.0.1], dsn=2.0.0, stat=Sent (qAJ7bRtP021022 Message accepted
for delivery)
Nov 19 01:37:37 VPS98889on sendmail[21024]: qAJ7bRtP021022:
to=<myhotmail@hotmail.com>, ctladdr=<root@VPS98889on>
(0/0), delay=00:00:10, xdelay=00:00:02, mailer=esmtp, pri=120420,
relay=mx3.hotmail.com. [65.55.92.184], dsn=2.0.0, stat=Sent (
<201211190737.qAJ7bQwu021021@VPS98889on> Queued mail for
delivery)
主要看延迟了1分钟的“My unqualified host name (VPS98889on) unknown;
sleeping for retry”,sendmail监听的是127.0.0.1,但无法确认主机名VPS98889on
(即HOSTNAME),原来是查询dns导致发送邮件非常慢,给vps本地host文件加条hostname的记录,vi
/etc/hosts:
127.0.0.1 localhost localhost.localdomain localhost4
localhost4.localdomain4 改为
127.0.0.1 localhost localhost.localdomain localhost4
localhost4.localdomain4 VPS98889on
(注意测试中发现另起一行添加hostname的A记录设置会无效:127.0.0.1
VPS98889on,是什么原因呢?),然后重启sendmail服务:service sendmail restart
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
这时如果发现重启sendmail 的速度也很快了,说明可以了。
过了段时间发现sendmail发送邮件又开始失败了,查看日志:
----- Transcript of session follows -----
... while talking to mx4.hotmail.com.:
>>> MAIL From:<apache@localhost.localdomain> SIZE=2625 BODY=8BITMIME
<<< 550 OU-001 (BAY0-MC1-F11) Unfortunately, messages from xxx.xx.xxx.xx weren't sent. Please contact your Internet service provider since part of their network is on our block list. You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors.
554 5.0.0 Service unavailable
... while talking to mta5.am0.yahoodns.net.:
<<< 553 5.7.1 [BL21] Connections will not be accepted from xxx.xx.xxx.xx, because the ip is in Spamhaus's list; see http://postmaster.yahoo.com/550-bl23.html
554 5.0.0 Service unavailable
在这里检查下确实这个ip又进入了spamhaus的数据库: http://whatismyipaddress.com/blacklist-check。没办法先换ip把。