...
运维

ubuntu安装配置heirloom-mailx使用外部smtp发送外网email

1.安装mailutils

系统

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

安装 mailutils

apt install -y mailutils

出现窗口 一路ok就行


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

看日志是 没有安装  postfix

# 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


更新并安装 heirloom-mailx

# 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


常用命令

n:不读入设置文件(本系统中是/etc/s-nail.rc)(这个文件允许用户使用外部邮件传输代理而不是使用系统自带的sendmail发送邮件)。
s:设置邮件的主题信息。
c:使用一个抄送列表。
b:使用一个密送列表。
a: 添加一个附件

举例

echo "内容"|s-nail -s "主题" xxxx@163.com,xxxx@outlook.com #多个邮箱用逗号隔开
#或者:
s-nail -s "邮件主题" xxx@163.com < result.txt

ps:加参数v可以看到mail输出的详细信息
s-nail -vs "邮件主题" xxx@163.com < result.txt

#发送带附件邮件
s-nail -a 附件 -s "主题" 收件地址 < 文件(邮件正文.txt)
s-nail -a /xxx.tar.gz -s "主题" xxx@163.com < ./xxx.txt

#shell 当编辑器,编辑完内容后按Ctrl-D结束
s-nail -s '主题‘ xxx@163.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


QQ邮箱收到邮件。


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. 禁止系统检查邮件




mysql 数据库恢复 frm,ibd文件恢复数据 数据库修复 做了一个文件监听然后同步到邮箱的小软件,可备份速达的备份!
biu biu biu
js时间转化为几天前,几小时前,几分钟前 Liunx命令大全 php身份证号验证 小程序遇到的坑,图片下载 downloadfile合法域名 一行代码手机端使用开发者工具调试网页