使用方法是:将要发送的内容以下面的形式组织,
- $ 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
脚本很简单:
- #! /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