CentOS下通过postfix使用自己的sina邮箱发送邮件

1、在/etc/postfix/main.cf文件末尾添加如下字段。

vim /etc/postfix/main.cf

smtp_sasl_security_options = noanonymous
relayhost = [smtp.sina.cn]:465
smtp_use_tls = yes
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd

2、配置SASL认证

创建passwd文件并添加账号密码信息

mkdir -p /etc/postfix/sasl

vim /etc/postfix/sasl/passwd

[smtp.sina.cn]:465 你的邮箱:应用专用密码
  • 注意邮箱账号和密码之间的“:",不要漏掉。例如:我公司购买的google邮箱服务,我生成的密码是123qwe则配置[smtp.gmail.com]:587 xiaoming@gongsi.com:123qwe
  • 由于google的安全限制,使用非web方式使用需要设置【应用专用密码】
  • 应用专用密码生成网站:https://security.google.com/settings/security/apppasswords

我的是sina邮箱,没有这个专用密码

3、更改文件权限

chmod 600 /etc/postfix/sasl/passwd

4、创建查找表

postmap /etc/postfix/sasl/passwd

5、生成CA证书

cd /etc/pki/tls/certs

make sam.pem               #例如:我叫小明,则 make xiaoming.pem


[root@sam certs]# make sam.pem
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2  ; \
cat $PEM1 >  sam.pem ; \
echo ""    >> sam.pem ; \
cat $PEM2 >> sam.pem ; \
rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
......................................................+++
................................................................................................................................................+++
writing new private key to '/tmp/openssl.S8x60X'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----


Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:gongsi
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:邮箱用户名  ## 邮箱用户名换成自己的邮箱名
Email Address []:  邮箱用户名@sina.cn

cp /etc/pki/tls/certs/sam.pem /etc/postfix/cacert.pem

7、重启postfix服务

service postfix restart

echo “hehezzz” | mailx -v -s “test” tiehan@sina.cn

参考资料

这里是一个广告位,,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn