1. 安装
$ su
Ubuntu
$ apt install postfix mailutils mpack mutt
Fedora
$ dnf install postfix mailx mutt
CentOS
$ yum install postfix mailx mutt cyrus-sasl cyrus-sasl-plain
OpenSUSE
$ zypper install postfix mailx mutt cyrus-sasl
* mpack / mailx / mutt 可选择只安装一个
* Fedora / CentOS 建议先解决 SELINUX 问题
http://jasonmun.blogspot.my/2017/01/centos-fedora-postfix-selinux.html
2. 设置
$ gedit /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 username@gmail.com:password
$ chmod 600 /etc/postfix/sasl_passwd
$ gedit /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
Ubuntu
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Fedora / CentOS
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
OpenSUSE
smtp_tls_CAfile = /etc/ssl/ca-bundle.pem
$ gedit /etc/postfix/master.cf
tlsmgr unix - - n 1000? 1 tlsmgr
3. 设置 - GOOGLE
i) Settings - Forwarding and POP/IMAP - IMAP Access - Enable IMAP
https://mail.google.com/mail/u/0/#settings/fwdandpop
ii) 修改步骤 2 的 password
Sign-in & security - Signing in to Google - 2-Step Verification - ON
Sign-in & security - Signing in to Google - App passwords
这个用 App Password
Sign-in & security - Signing in to Google - 2-Step Verification - Off
Sign-in & security - Connected apps & sites - Allow less secure apps: ON
这个用 Gmail Password
https://myaccount.google.com/security?utm_source=OGB#signin
4. 重启
$ postmap /etc/postfix/sasl_passwd
$ systemctl restart postfix
5. 在防火壁增加 PORT 25
Ubuntu
$ ufw allow Postfix
CentOS / Fedora
$ firewall-cmd --add-service=smtp --permanent
或
$ firewall-cmd --add-port=25/tcp --permanent
$ firewall-cmd --reload
OpenSUSE
YaST - Firewall - Allowed Services - Service to Allow : SMTP with Postfix - Add
6. 测试
$ echo "This is a test" | mail -s "Subject" recipient@yahoo.com
$ echo "This is a test" | mail -s "Subject" recipient@yahoo.com -A /home/user/content.txt
# OpenSUSE 用 mailx 要将 -a 改为 -A
$ echo "This is a test" | mailx -s "Subject" recipient@yahoo.com -a /home/user/content.txt
$ echo "This is a test" | mutt -s "Subject" recipient@yahoo.com -a /home/user/content.txt
$ mpack -s "Test File" /home/user/content.txt recipient@yahoo.com
7. 其它
Ubuntu - postfix - Host not found 解决方法
没有评论:
发表评论