https://www.cnblogs.com/github-cn/archive/2019/08/01/11281961.html

https://segmentfault.com/q/1010000004497746/a-1020000004501310

1、下载ssmtp(适用于内置 mail 命令的机器)

1
sudo apt-get install ssmtp

重启邮件服务

1
2
3
4
service  stop sendmail / systemctl stop sendmail
service start sendmail / systemctl start sendmail
systemctl start sendmail / systemctl stop postfix
systemctl start sendmail / systemctl stop postfix

2、配置 /etc/ssmtp/ssmtp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=xxxxxxx@qq.com

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.exmail.qq.com:587
AuthUser=xxxxxxx@qq.com
AuthPass=xxxxxxxx
UseTLS=YES
UseSTARTTLS=YES
# Where will the mail seem to come from?
#rewriteDomain=

rewriteDomain=ghubserver
# The full hostname
hostname=xxxxxxx

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

hostname=xxxxxxx@qq.com

or vim /etc/mail.rc

1
2
3
4
5
6
set append dot save ask crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via

set from=xxxxxxx@qq.com smtp="smtp.exmail.qq.com:587"
set smtp-auth-user="xxxxxxx@qq.com" smtp-auth-password="xxxxxx"
set smtp-auth=login

vim /etc/ssmtp/revaliases

1
2
3
4
5
6
7
8
# sSMTP aliases
#
# Format: local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.
www:xxxxxxx@qq.com:smtp.exmail.qq.com:587
mainuser:xxxxxxx@qq.com:smtp.exmail.qq.com:587

最后记得配置安全组 25 or 587 or …