在命令行配置邮件发送服务

基本要求

  • 具备可访问的内部/外部smtp服务

配置步骤

安装 ssmtp 命令

1
2
apt update
apt install ssmtp mailutils

配置 ssmtp

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

# 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.hlmg.tech:465

# Where will the mail seem to come from?
rewriteDomain=mail.hlmg.tech

AuthUser=notice@hlmg.tech
AuthPass=xxxxxxxxxxxxxxxxxxxxxxxx
UseTLS=YES
AuthMethod=LOGIN
# The full hostname
hostname=mail.hlmg.tech:465

# 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=NO

编辑别名:

1
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:notice@hlmg.tech:mail.hlmg.tech:465

该配置将root用户配置为指定的发件方式。

测试发件

1
2
echo -e "Subject: Test Mail\nThis is the mail body" > /tmp/ssmtp-mail.txt
ssmtp admin@hlmg.tech < /tmp/ssmtp-mail.txt

验证完成后,可通过 mail 命令或者 ssmtp 命令发件:

1
mail -s "Backup successfully" -a "From: Mailu Server Backup <notice@hlmg.tech>" wall@hlmg.tech < daily_backup.log
使用 Hugo 构建
主题 StackJimmy 设计