前几天,由于业务需要,学习了下命令行下如何发送邮件,总结成本文。
首先,安装mailx
$ yum install mailx
其次,配置服务
# /etc/mail.rc ignore mime-version content-transfer-encoding # Only include selected header fields when forwarding messages. fwdretain subject date from to # For Linux and BSD, this should be set. set bsdcompat set from=sky-notify@yhd.com set smtp= mail.hotdian.com.cn
配置邮件源地址(发送给对方时,显示的发件人)
配置邮件服务器地址这样就可以使用mail命令发邮件了。
发邮件
方式一:
$ echo "hello" | mail -s "Hello from me" lanyang@hotdian.com
‘-s’ 是邮件主题,后面紧跟收件人地址
方式二:
从文件读取发送内容$ mail -s "look at this" lanyang@hotdian.com < mail_content.txt
问题
问题1:
send-mail: warning: inet_protocols: IPv6 support is disabled:Address family not supported by protocol
send-mail: warning: inet_protocols: configuring for IPv4 supportonly
postdrop: warning: inet_protocols: IPv6 support is disabled:Address family not supported by protocol
postdrop: warning: inet_protocols: configuring for IPv4 supportonly解决办法:
# vi /etc/postfix/main.cf inet_protocols = all 改为 inet_protocols = ipv4
问题2:
不支持中文,尚未解决。sendmail似乎支持,待后续验证。