ubuntu通过mail命令发送邮件

我们知道在centos系统里有个mail命令,可以发送邮件
安装

yum install mailx -y

配置/etc/mail.rc

vi /etc/mail.rc

# 指定邮箱
set from=5......83@qq.com
 
# 邮箱协议
set smtp="smtp.qq.com"
 
# 邮箱账号
set smtp-auth-user="5......83@qq.com"
 
# 邮箱授权码,QQ邮箱后台里面去授权
set smtp-auth-password="*****"
 
# 登陆方式
set smtp-auth=login

然后就可以通过mail命令发送邮件了

echo "hello" | mail -s "hello testmail" .....@......
 
# 参数
-s 邮件标题
echo "hell0" 邮件的内容

# 或者通过一个文件发送
mail -s "this is test mail" .......@..... < /tmp/mail_content.txt

在ubuntu系统怎么安装呢?

sudo apt install heirloom-mailx

报错:Package has no installation candidate,这可能是源的问题,如下解决

sudo vim /etc/apt/sources.list

在文件末端加入:

deb http://cz.archive.ubuntu.com/ubuntu xenial main universe

更新

apt update

安装

sudo apt install heirloom-mailx

配置,在文尾加入,注意这里是/etc/s-nail.rc,不是/etc/mail.rc

sudo vi /etc/s-nail.rc

set from=.....@126.com
set smtp=smtp.126.com
set smtp-auth-user=.....@126.com
set smtp-auth-password=t45.....
set smtp-auth=login

发送邮件测试一下

echo "hello world,this is a test mail" | heirloom-mailx -s "hello mail" 28..........11@qq.com

我这里以126.com邮箱为例,要开启smtp功能,其他邮箱如qq邮箱也是一样的


126-mail.png

好了,到此为止,希望对你有帮助

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容