作者:晨曦微露jie | 来源:互联网 | 2014-05-28 08:57
#!/bin/bash#sendahtml-emailusingsendmailcommand#author:mlsxmlsx(dot)xplore(at)gmail(dot)com#license:GPLfrom”my@mydomain.com”subject”testhtml-emailusingmailcomma
#!/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
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