全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
12
返回列表 发新帖
楼主: house
打印 上一主题 下一主题

[疑问] 求sendmail发邮件的命令

[复制链接]
11#
 楼主| 发表于 2012-7-31 20:14:17 | 只看该作者
远坂时臣 发表于 2012-7-31 19:53
这点东西不用php吧

求进阶,如何添加附件
12#
发表于 2012-7-31 20:17:45 | 只看该作者
  1. #!/bin/bash
  2. #requires: basename,date,md5sum,sed,sendmail,uuencode
  3. function fappend {
  4.     echo "$2">>$1;
  5. }
  6. YYYYMMDD=`date +%Y%m%d`

  7. # CHANGE THESE
  8. TOEMAIL="[email protected]";
  9. FREMAIL="[email protected]";
  10. SUBJECT="Daily Backup - $YYYYMMDD";
  11. MSGBODY="Hello this is the message body";
  12. ATTACHMENT="/home/joeuser/Untitled.png"
  13. MIMETYPE="image/png" #if not sure, use http://www.webmaster-toolkit.com/mime-types.shtml

  14. # DON'T CHANGE ANYTHING BELOW
  15. TMP="/tmp/tmpfil_123"$RANDOM;
  16. BOUNDARY=`date +%s|md5sum`
  17. BOUNDARY=${BOUNDARY:0:32}
  18. FILENAME=`basename $ATTACHMENT`

  19. rm -rf $TMP;
  20. cat $ATTACHMENT|uuencode --base64 $FILENAME>$TMP;
  21. sed -i -e '1,1d' -e '$d' $TMP;#removes first & last lines from $TMP
  22. DATA=`cat $TMP`

  23. rm -rf $TMP;
  24. fappend $TMP "From: $FREMAIL";
  25. fappend $TMP "To: $TOEMAIL";
  26. fappend $TMP "Reply-To: $FREMAIL";
  27. fappend $TMP "Subject: $SUBJECT";
  28. fappend $TMP "Content-Type: multipart/mixed; boundary=""$BOUNDARY""";
  29. fappend $TMP "";
  30. fappend $TMP "This is a MIME formatted message.  If you see this text it means that your";
  31. fappend $TMP "email software does not support MIME formatted messages.";
  32. fappend $TMP "";
  33. fappend $TMP "--$BOUNDARY";
  34. fappend $TMP "Content-Type: text/plain; charset=ISO-8859-1; format=flowed";
  35. fappend $TMP "Content-Transfer-Encoding: 7bit";
  36. fappend $TMP "Content-Disposition: inline";
  37. fappend $TMP "";
  38. fappend $TMP "$MSGBODY";
  39. fappend $TMP "";
  40. fappend $TMP "";
  41. fappend $TMP "--$BOUNDARY";
  42. fappend $TMP "Content-Type: $MIMETYPE; name="$FILENAME"";
  43. fappend $TMP "Content-Transfer-Encoding: base64";
  44. fappend $TMP "Content-Disposition: attachment; filename="$FILENAME";";
  45. fappend $TMP "";
  46. fappend $TMP "$DATA";
  47. fappend $TMP "";
  48. fappend $TMP "";
  49. fappend $TMP "--$BOUNDARY--";
  50. fappend $TMP "";
  51. fappend $TMP "";
  52. #cat $TMP>out.txt
  53. cat $TMP|sendmail -t;
  54. rm $TMP;
复制代码
13#
发表于 2012-7-31 21:22:06 | 只看该作者
house 发表于 2012-7-31 20:14
求进阶,如何添加附件

要这么多的功能,就不要在shell上做了,用php吧,shell不适合做复杂的操作~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-15 16:11 , Processed in 0.066635 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表