First, DNS configuration
Type |
name |
value |
TTL |
A |
Mail |
128.199.254.32 |
1 hours |
Mx |
@ |
mail.example.com ( priority:Ten) |
1 hours |
Txt |
@ |
v=spf1 mx:mail.example.com ip4:128.199.254.32 ~all |
1 hours |
TXT |
Mail._domain |
KeyV=dkim1;k=rsa; P=migfma0gcsqgsi ... |
1 hours |
Where you can configure A and MX records first,
Two txt records are used for "anti-spam ", where Dkim requires a native configuration, which is described in detail later in this article.
Second, Postfix Installation and Configuration
2.1 set it up beforehand. hostname ,Postfix can automatically configure a lot of parameters, save time.
Echo "example.com" >/etc/hostname
2.2 Installing postfix
Install mailutils
The default option is Internet Site , fill example.com Press ENTER.
2.3 Basic Configuration
Modify a file /etc/postfix/main.cf
= = = = Loopback-only
Then restart the service.
# systemctl Restart Postfix
2.4 now can send e-mail, test to see if you can receive.
Echo "Body of the email" | Mail-s "Subject line" your_email_address
2.5 (optional configuration) to use TLS encryption
third, anti-spam settings: SPF ,DKIM and DMARC
3.1 SPF just add DNS Records, here 's the point. DKIM installation configuration
Install Opendkim opendkim-tools
3.2 Edit File/etc/opendkim.conf append the following configuration to the bottom of the file:autorestart Yesautorestartrate Ten/1h
UMask002Syslog yessyslogsuccess yeslogwhy yescanonicalization relaxed/simpleexternalignorelist refile:/etc/opendkim/trustedhostsinternalhosts refile:/etc/opendkim/trustedhostskeytable refile:/etc/opendkim/keytablesigningtable refile:/etc/opendkim/Signingtablemode Svpidfile/var/run/opendkim/opendkim.pidsignaturealgorithm RSA-sha256
UserID opendkim:opendkimsocket inet:12301@localhost
3.3 Edit/etc/default/opendkim, comment out the original socket configuration, add new configuration:
socket="inet:[email protected]"
3.4 Edit/etc/postfix/main.cf, Add the following configuration:
6 milter_default_action = Accept
Among them, when the postfix version is 2.6+, milter_protocol=6; The version is 2.3 to 2.5, milter_protocol=2;
View Postfix version information:
grep mail_version
If you already have smtpd_milters and non_smtpd_milters configurations, append the following:
Smtpd_milters = Unix:/spamass/spamass.sock, inet:localhost:12301 non_smtpd_milters = unix:/spamass/ Spamass.sock, Inet:localhost:12301
If there is no related configuration, use it directly:
Smtpd_milters = inet:localhost:12301 non_smtpd_milters = inet:localhost:12301
3.5 Execute the following command
sudo mkdir sudo mkdir /etc/opendkim/keys
3.6 Create/etc/opendkim/trustedhosts, the first three lines do not change
127.0. 0.1 localhost 192.168. 0.1/ *.example.com
3.7 Create /etc/opendkim/keytable
Mail._domainkey.example.com example.com:mail:/etc/opendkim/keys/example.com/mail.private
3.8 Create /etc/opendkim/signingtable
* @example. com mail._domainkey.example.com
3.9 Execute the following command:
sudo mkdir sudo opendkim-genkey-sudochown Opendkim:opendkim Mail.private
3.10 Next, create a DNS TXT record:
which , name is mail._domainkey
Value to refer to/etc/opendkim/keys/example.com/mail.txt, in the format:
V=DKIM1; K=rsa; P=migfma0gcsqgsib3dqebaquaa4gnadcbiqkbgqc5n3lnvvrygpcrsoqn+awtpe+ Igyckbppo8hhbcffciiv10hwo4phcogzsakvhojdm4yefkxhqjm7ikzepubate7o47hax1cjpnuidlxhilsbembmxjrjag0hzvn8z6eaoohznaphmk2h4uurj Og8za5bhfzjf7tgwi+k619ffuwidaqab
3.11 Restart the service.
sudo sudo service opendkim restart
If you have errors, check the logs:/var/log/mail.err and/var/log/mail.log
Reference Documentation:
[1]" How to install and configure Postfix on Ubuntu 16.04 as only sending SMTP server ",/ HTTP/ blog.csdn.net/zstack_org/article/details/69525954
[2]"Email Basics SPF Setting Description ", https://tieba.baidu.com/p/3166555301?red_tag= 1967972912
[3]" support for message encryption with SSL Postfix+ssl configuration ", http://shellyli.iteye.com/blog/1534717
Ubuntu16.04 build postfix as SMTP server