原先上海交通大學ACM班 Transactional Mail 是直接用自建的 postfix 發的,自建郵箱最擔心的事情就是被當作垃圾郵件。然而畢竟域名DNS以及IP反向DNS都不在自己手上,似乎沒有任何辦法可以改變這個窘境。昨天想了個權宜之計,換一個域名來發郵件。

要想發出的郵件不被當作垃圾郵件,可以從下面這幾個方面入手:

確保IP不在黑名單內

設定IP的反向DNS(需要IP提供商支援)

設定SPF記錄(域名DNS中新增TXT記錄)

設定DKIM記錄(伺服器配置+域名DNS中新增TXT記錄)

設定DMARC記錄(伺服器配置+域名DNS中新增TXT記錄)

不亂髮郵件

……

自建郵箱參考資料

跟著做就好了:

IP黑名單查詢:Blocklist Removal Center

安裝Postfix: How to Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 16。04

Postfix繫結IP:How to make Postfix use another IP address?

配置SPF:How To use an SPF Record to Prevent Spoofing &; Improve E-mail Reliability

配置DKIM:How To Install and Configure DKIM with Postfix on Debian Wheezy

配置DMARC:How to eliminate spam and protect your name with DMARC

除錯技巧

配置好了之後可以試著給不同的郵箱發郵件,看看會不會被當作垃圾郵件。

sudo apt-get install heirloom-mailx

echo

test

body

|

mailx -S

smtp

=

127。0。0。1 -r noreply@example。com -s

“test subject”

-v example@gmail。com

然後可以在收信郵箱檢視原始郵件,看看頭部資訊就可以知道這些配置有沒有起作用

Authentication-Results: mx4。messagingengine。com;

arc=none (no signatures found);

dkim=pass (1024-bit rsa key sha256) header。d=example。com header。i=@example。com header。b=XVDsyrZV x-bits=1024 x-keytype=rsa x-algorithm=sha256 x-selector=mail;

dmarc=pass header。from=example。com;

iprev=fail policy。iprev=1。2。3。4 (Error NXDOMAIN looking up 1。2。3。4 PTR,NOT FOUND);

spf=pass smtp。mailfrom=noreply@example。com smtp。helo=example。com;

x-aligned-from=pass;

x-category=clean score=0 state=0;

x-ptr=fail x-ptr-helo=example。com x-ptr-lookup=;

x-return-mx=pass smtp。domain=example。com smtp。result=pass smtp_is_org_domain=yes header。domain=example。com header。result=pass header_is_org_domain=yes

比方說這裡我們就可以看到 DKIM / DMARC / SPF 都通過了,但是找不到IP的反向DNS。不過我也配置不了反向DNS,所以基本上到此為止了。我試了試,往 Gmail / Fastmail / 126 / QQ 都能正常收到收件箱,還是不錯的。

首發於部落格:自建事務郵件發件伺服器