Mailx 安装与使用 #
Mailx 安装 #
安装 #
执行命令
sudo yum install -y mailx
配置 #
在配置文件 /etc/mail.rc
后面追加
set from=username@domain # 对方收到邮件时显示的发件人
set smtp=smtp.domain.com # 指定第三方发送邮件的smtp服务器地址
set smtp-auth-user=username@domain # 第三方发邮件的用户名
set smtp-auth-password="password" # 用户名对应密码或授权码
set smtp-auth=login # SMTP的认证方式。默认是LOGIN,也可改为CRAM-MD5或PLAIN方式
Mailx的使用 #
可以使用 mail -h
查看帮助
mail: option requires an argument -- h
Usage: mail -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -cUSERS -S OPTION users
无正文的邮件 #
mail -s "subject" [email protected]
注:不知道是我的版本的问题还是其他原因,我使用这种方式是发不出去邮件的,执行后一直没有响应,程序像是挂起了一样,既不发送也不结束。
有正文的邮件 #
从文件中导入正文 #
mail -s "subject" [email protected] < message_body.txt
或者
cat message_body.txt | mail -s "subject" [email protected]
从命令行导入正文 #
echo "massage body content" | mail -s "subject" [email protected]
带附件的邮件 #
mail -s "subject" [email protected] -a attachment.tar.gz