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

参考:

  1. mail: 在linux上通过命令行发送邮件
  2. Linux 命令行发送邮件的 5 种方法
  3. ubuntu18.04 heirloom-mailx 通过外部SMTP服务器发送邮件
  4. 禁止系统检查邮件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值