Chinaunix首页 | 论坛 | 博客
  • 博客访问: 153984
  • 博文数量: 13
  • 博客积分: 45
  • 博客等级: 民兵
  • 技术积分: 871
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-02 10:59
个人简介

Nobody.

文章分类

全部博文(13)

文章存档

2013年(13)

分类: 系统运维

2013-07-10 09:15:17

在测试邮件内容审查软件时,遇到频繁发送邮件的情况,索性写了个自动发送邮件的脚本。
使用方法是:将要发送的内容以下面的形式组织,

  1. $ tree mails/
  2. mails/
  3. |-- mail1
  4. | |-- attach1
  5. | |-- attach2
  6. | |-- attach3
  7. | |-- attachment.lst
  8. | |-- body.txt
  9. | |-- receiver.lst
  10. | `-- subject.txt
  11. |-- mail2
  12. | |-- attach1
  13. | |-- attach2
  14. | |-- attach3
  15. | |-- attachment.lst
  16. | |-- body.txt
  17. | |-- receiver.lst
  18. | `-- subject.txt
  19. `-- mail3
  20. |-- attach1
  21. |-- attach2
  22. |-- attach3
  23. |-- attachment.lst
  24. |-- body.txt
  25. |-- receiver.lst
  26. `-- subject.txt
其中receiver.lst是收件人列表,subject.txt是主题,body.txt是正文,attachment.lst是附件列表,attach1、attach2、attach3是attachment.lst中列出的附件,每个mailN文件夹是一封邮件。
脚本很简单:

  1. #! /bin/bash
  2. # Auto send email
  3. #
  4. if [[ $# < 1 ]]
  5. then
  6. echo "Usage: $0 "
  7. exit
  8. fi
  9. DIR="$1"
  10. cd "$DIR" || { echo "Enter $DIR failed"; exit; }
  11. for dir in $(ls -d */)
  12. do
  13. cd "$dir" || { echo "Enter $dir failed"; continue; }
  14. receiver=$(cat receiver.lst | sed ':a; $!N; s/\n/ /; ta')
  15. subject=$(cat subject.txt)
  16. body=$(cat body.txt)
  17. attachment=$(cat attachment.lst | sed ':a; $!N; s/\n/ -a /; ta')
  18. echo "$body" | mutt -s "$subject" -a $attachment $receiver
  19. echo "Send $dir"
  20. cd ..
  21. done
阅读(2618) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~