ubuntu使用ssmtp mailutils发送邮件

https://blog.csdn.net/u010953692/article/details/121744436 (主要参考)

一. 安装软件

1
2
# 安装用于发送邮件的软件
apt install -y ssmtp mailutils

二. 修改配置文件

vim /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
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=postmaster

# 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=mail
mailhub=smtp.qq.com:465
# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=gegewu
UseTLS=Yes
root=123456@qq.com
AuthUser=123456
AuthPass=bryatscojpvpbcec
# 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

vim /etc/ssmtp/revaliases

1
2
3
4
5
6
7
# 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.
root:123456@qq.com:smtp.qq.com:465

发送邮件

1
2
3
4
5
3. 测试发送邮件:
# 发送单人
echo "nginx状态测试勿回复" | mail -s "测试负载均衡器告警" 123456@qq.com
# 同时发送多人后面接逗号即可
echo "nginx状态测试勿回复" | mail -s "测试负载均衡器告警" 123456@qq.com,12345678@qq.com

三. 效果

image-20230521212420363