ubuntu通过mail命令发送邮件

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

yum install mailx -y

配置/etc/mail.rc

vi /etc/mail.rc

# 指定邮箱
set [email protected]
 
# 邮箱协议
set smtp="smtp.qq.com"
 
# 邮箱账号
set smtp-auth-user="[email protected]"
 
# 邮箱授权码,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 [email protected]
set smtp=smtp.126.com
set [email protected]
set smtp-auth-password=t45.....
set smtp-auth=login

发送邮件测试一下

echo "hello world,this is a test mail" | heirloom-mailx -s "hello mail" [email protected]

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


126-mail.png

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

你可能感兴趣的:(ubuntu通过mail命令发送邮件)