手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >Shell脚本实现自动发送邮件的例子
Shell脚本实现自动发送邮件的例子
摘要:1、编辑用户Home目录下的.muttrc文件,设置发信环境。复制代码代码如下:#cat/root/.muttrcsetenvelope_f...

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许可。

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

【Shell脚本实现自动发送邮件的例子】相关文章:

在Shell中分割字符串的例子

shell实现自动备份mysql、整站数据的两个脚本分享

shell实现数字打印从100到200的数

Shell脚本获取进程的运行时间

5个Shell脚本编程入门练习例子

Shell脚本定时备份清除运行系统日志的代码

Shell脚本判断IP地址是否合法的方法

shell脚本命令行参数简介

25个好用的Shell脚本常用命令分享

shell脚本从SVN推送到多台服务器的代码

精品推荐
分类导航