一、安装mailx
yum install mailx
二、配置mailx
配置修改/etc/mail.rc配置文件(如果mail.rc不存在,则编辑/etc/nail.rc)。
在/etc/mail.rc文件末尾添加如下内容:
set from="your name"
set smtp=smtp.163.com
set smtp-auth-user=mailname@163.com
set smtp-auth-password=password
set smtp-auth=login
注:使用前需打开邮箱的SMTP功能,一般在邮箱的设置里面。
三、使用mailx发送邮件
-s subject 邮件标题
-a file 添加附件
-v 显示邮件发送详细过程
-V 显示mail(mailx)版本信息
邮件内容可来源于管道、输入重定向等,例如:
mailx -s "发件人名称 邮件标题" mailname@163.com < message.txt
cat message | mailx -s "发件人名称 邮件标题" mailname@163.com
echo "mail test message" | mailx -v -s " title" mailnamexxx3@163.com
也可以直接从命令行输入邮件内容:
mailx -s "发件人名称 邮件标题" mailname@163.com ##输入完后回车按Ctrl+D提交发送
多个收件人之间用逗号分隔:
cat message | mailx -s "发件人名称 邮件标题" mail1@163.com, mail2@163.com, mail3@163.com