您的位置:首页 > 运维架构 > Shell

Shell脚本实现自动发送邮件的例子

2014-08-29 00:00 691 查看
1、编辑用户Home目录下的.muttrc文件,设置发信环境。

# cat /root/.muttrc 

set envelope_from=yes

set from=owinux@sina.cn

set realname="Owinux"

set use_from=yes

set rfc2047_parameters=yes

set charset="utf-8"

2、发信脚本

# cat automail.sh 

#!/bin/sh

# automail.sh

DIR=/root/owinux

mailcontent=$DIR/mailcontent

> "$mailcontent"

echo -e "owinux,您好!\n" >> $mailcontent

echo -e "\t附件为 `date +%Y-%m-%d` 设备日检报告,敬请查收。" >> $mailcontent

cat mailcontent | /usr/bin/mutt -s "设备日检报告" -a /root/owinux/report.xls owinux@126.com -c owinux@yeah.net -c owinux@sina.com

3、简要说明:



-s:指定主题

-a:附件

-c:抄送,需要抄送多人的话,须使用多个 -c 选项



使用上面的发信环境可以保证在页面查看邮件的时候,附件名不出现乱码。

其中 .muttrc 的 "set from"可以随便设置,可以是不存在的邮箱地址,当然正确的最好。

比如:

set from=abc@owinux.com

不过也并不是你设置的正确的邮箱地址就一定能发送成功。

set from=owinux@126.com

我新注册了一个 owinux@126.com,然后将 set from 设置为owinux@126.com,就没有成功。

原因在于126邮箱报了 550 MI:SPF 错误,连接到126 企业退信的常见问题? 发现

550 MI:SPF 发信IP未被发送域的SPF许可。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: