Linux 使用命令发送邮件

1、安装邮件服务
yum -y install mailx
 
源码包安装
mailx
wget http://ftp.debian.org/debian/pool/main/h/heirloom-mailx/heirloom-mailx_12.5.orig.tar.gz
tar zxvf heirloom-mailx_12.5.orig.tar.gz
cd heirloom-mailx-12.5/
make && make install UCBINSTALL=/usr/bin/install
 
2、然后修改/etc/mail.rc,在文件末尾增加以下内容,指定外部的smtp服务器地址、帐号密码等
1 $ vi /etc/mail.rc  
2 set from=123456@qq.com
3 set smtp=smtp.qq.com  
4 set smtp-auth-user=123456
5 set smtp-auth-password=密码或授权码 
6 set smtp-auth=login

 

3、然后通过命令来发送邮件
echo "hello word" | mail -s " title" 123456@qq.com
echo "hello word" | mail -s " title" -a /mnt/file.txt 123456@qq.com    #带附件发送

posted @ 2020-12-22 21:49  局域网外  阅读(408)  评论(0编辑  收藏  举报