找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
楼主: house

求sendmail发邮件的命令

[复制链接]

17

主题

159

回帖

371

积分

中级会员

积分
371
发表于 2012-7-31 19:55:13 | 显示全部楼层
[ol]
  • #!/bin/bash
  • #requires: basename,date,md5sum,sed,sendmail,uuencode
  • function fappend {
  •     echo "$2">>$1;
  • }
  • YYYYMMDD=`date +%Y%m%d`
  • # CHANGE THESE
  • TOEMAIL="recipient@email.com";
  • FREMAIL="crondaemon@65.244.254.144";
  • SUBJECT="Daily Backup - $YYYYMMDD";
  • MSGBODY="Hello this is the message body";
  • ATTACHMENT="/home/joeuser/Untitled.png"
  • MIMETYPE="image/png" #if not sure, use http://www.webmaster-toolkit.com/mime-types.shtml
  • # DON'T CHANGE ANYTHING BELOW
  • TMP="/tmp/tmpfil_123"$RANDOM;
  • BOUNDARY=`date +%s|md5sum`
  • BOUNDARY=${BOUNDARY:0:32}
  • FILENAME=`basename $ATTACHMENT`
  • rm -rf $TMP;
  • cat $ATTACHMENT|uuencode --base64 $FILENAME>$TMP;
  • sed -i -e '1,1d' -e '$d' $TMP;#removes first & last lines from $TMP
  • DATA=`cat $TMP`
  • rm -rf $TMP;
  • fappend $TMP "From: $FREMAIL";
  • fappend $TMP "To: $TOEMAIL";
  • fappend $TMP "Reply-To: $FREMAIL";
  • fappend $TMP "Subject: $SUBJECT";
  • fappend $TMP "Content-Type: multipart/mixed; boundary=""$BOUNDARY""";
  • fappend $TMP "";
  • fappend $TMP "This is a MIME formatted message.  If you see this text it means that your";
  • fappend $TMP "email software does not support MIME formatted messages.";
  • fappend $TMP "";
  • fappend $TMP "--$BOUNDARY";
  • fappend $TMP "Content-Type: text/plain; charset=ISO-8859-1; format=flowed";
  • fappend $TMP "Content-Transfer-Encoding: 7bit";
  • fappend $TMP "Content-Disposition: inline";
  • fappend $TMP "";
  • fappend $TMP "$MSGBODY";
  • fappend $TMP "";
  • fappend $TMP "";
  • fappend $TMP "--$BOUNDARY";
  • fappend $TMP "Content-Type: $MIMETYPE; name="$FILENAME"";
  • fappend $TMP "Content-Transfer-Encoding: base64";
  • fappend $TMP "Content-Disposition: attachment; filename="$FILENAME";";
  • fappend $TMP "";
  • fappend $TMP "$DATA";
  • fappend $TMP "";
  • fappend $TMP "";
  • fappend $TMP "--$BOUNDARY--";
  • fappend $TMP "";
  • fappend $TMP "";
  • #cat $TMP>out.txt
  • cat $TMP|sendmail -t;
  • rm $TMP;[/ol]复制代码
  • 回复

    使用道具 举报

    19

    主题

    216

    回帖

    509

    积分

    高级会员

    积分
    509
    发表于 2012-7-31 19:53:00 | 显示全部楼层

    house 发表于 2012-7-31 20:14



    求进阶,如何添加附件

    要这么多的功能,就不要在shell上做了,用php吧,shell不适合做复杂的操作~
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-1-11 20:55 , Processed in 0.019048 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

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