2014-07-13 20:26:03
来 源
中存储网
基础知识
#!/bin/bash #send a html-email using sendmail command #author:mlsxmlsx(dot)xplore(at)gmail(dot)com #license:GPL from=”my@mydomain.
    #!/bin/bash
    #send a html-email using sendmail command
    #author:mlsx mlsx(dot)xplore(at)gmail(dot)com
    #license:GPL
    from=”my@mydomain.com”
    subject=”test html-email using mail command”
    msgdate=`date +”%a, %e %Y %T %z”` # Leave alone
    emailtarget=”your@yourdomain.com”
    daemail=$(cat < Date: $msgdate
    From: $from
    To:$emailtarget
    Subject: $subject
    Mime-Version: 1.0
    Content-Type: text/html; charset=gb2312
    !)
    echo "$daemail" > msg.tmp
    echo >>msg.tmp
    cat test.html >>msg.tmp
    echo >> msg.tmp
    cat msg.tmp |sendmail -t
    rm -f msg.tmp    

这里是有这个问题的就是  “msgdate=`date +”%a, %e %Y %T %z”`”  来设置了发件时间,可实际上这样发出的邮件发件时间是不正确的,应该将这句和设置发件时间的语句去掉,正确的代码是下面的样子

    #!/bin/bash
    #send a html-email using sendmail command
    #author:mlsx mlsx(dot)xplore(at)gmail(dot)com
    #license:GPL
    from=”my@mydomain.com”
    subject=”test html-email using mail command”
    emailtarget=”your@yourdomain.com”
    daemail=$(cat <
    From: $from
    To:$emailtarget
    Subject: $subject
    Mime-Version: 1.0
    Content-Type: text/html; charset=gb2312
    !)
    echo "$daemail" > msg.tmp
    echo >>msg.tmp
    cat test.html >>msg.tmp
    echo >> msg.tmp
    cat msg.tmp |sendmail -t
    rm -f msg.tmp

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。