在测试邮件内容审查软件时,遇到频繁发送邮件的情况,索性写了个自动发送邮件的脚本。
使用方法是:将要发送的内容以下面的形式组织,
-
$ tree mails/
-
mails/
-
|-- mail1
-
| |-- attach1
-
| |-- attach2
-
| |-- attach3
-
| |-- attachment.lst
-
| |-- body.txt
-
| |-- receiver.lst
-
| `-- subject.txt
-
|-- mail2
-
| |-- attach1
-
| |-- attach2
-
| |-- attach3
-
| |-- attachment.lst
-
| |-- body.txt
-
| |-- receiver.lst
-
| `-- subject.txt
-
`-- mail3
-
|-- attach1
-
|-- attach2
-
|-- attach3
-
|-- attachment.lst
-
|-- body.txt
-
|-- receiver.lst
-
`-- subject.txt
其中receiver.lst是收件人列表,subject.txt是主题,body.txt是正文,attachment.lst是附件列表,attach1、attach2、attach3是attachment.lst中列出的附件,每个mailN文件夹是一封邮件。
脚本很简单:
-
#! /bin/bash
-
# Auto send email
-
#
-
if [[ $# < 1 ]]
-
then
-
echo "Usage: $0 "
-
exit
-
fi
-
DIR="$1"
-
cd "$DIR" || { echo "Enter $DIR failed"; exit; }
-
for dir in $(ls -d */)
-
do
-
cd "$dir" || { echo "Enter $dir failed"; continue; }
-
receiver=$(cat receiver.lst | sed ':a; $!N; s/\n/ /; ta')
-
subject=$(cat subject.txt)
-
body=$(cat body.txt)
-
attachment=$(cat attachment.lst | sed ':a; $!N; s/\n/ -a /; ta')
-
echo "$body" | mutt -s "$subject" -a $attachment $receiver
-
echo "Send $dir"
-
cd ..
-
done
阅读(2691) | 评论(0) | 转发(0) |