ubuntu linux命令行发送邮件 heirloom-mailx

  • Post author:
  • Post category:linux


ubuntu linux命令行发送邮件 heirloom-mailx

1,安装mailutils

系统

 cat /etc/issue
Ubuntu 18.04.4 LTS \n \l

apt install -y mailutils



2,mailutils配置

cat /usr/share/doc/mailutils/examples/mail.rc

3,发送邮件

发送邮件报错

# echo "This is the mail body" | mail -s "Subject" 邮箱
mail: cannot send message: Process exited with a non-zero status

查看日志

# tail /var/log/mail.err
May 22 15:52:21 zj01 postfix/sendmail[102701]: fatal: open /etc/postfix/main.cf: No such file or directory
May 22 16:34:18 zj01 postfix/sendmail[113790]: fatal: open /etc/postfix/main.cf: No such file or directory

4,安装postfix

apt-get install postfix

5,安装heirloom-mailx

添加源

# vim /etc/apt/sources.list
deb http://cz.archive.ubuntu.com/ubuntu xenial main universe
# apt update
# apt install heirloom-mailx -y

5.1,配置heirloom-mailx

    vim /etc/s-nail.rc添加到配置文件末尾
    使用网易邮箱,邮箱开启POP3/SMTP/IMAP服务

set from="网易邮箱@163.com"
set smtp="smtps://smtp.163.com:465"
set smtp-auth-user="网易邮箱@163.com"
set smtp-auth-password="授权码"
set smtp-auth=login

测试

echo "邮件内容" | s-nail  -s "邮件主题" QQ邮箱@qq.com

测试成功

报错

s-nail: smtp-server: 554 DT:SPM 163 smtp9,DcCowADH0GhpEdFeEW2WDg--.437S2 1590759786,please see http://mail.163.com/help/help_spam_16.htm?ip=223.247.87.181&hostid=smtp9&time=1590759786
/root/dead.letter 13/382
... message not sent

需要安装mailutils,成功发送测试邮件

# apt install -y mailutils

6,关闭邮件提示

终端会有邮件提示

您在 /var/mail/root 中有新邮件

mail查看邮件

# mail
"/var/mail/root": 14 messages 14 new
>N   1 Cron Daemon        六 5月 30 00:0  23/958   Cron <root@zj> /bin/bash /root/mail.sh

关闭提示

echo "unset MAILCHECK" >> /etc/profile