在perl中邮寄日志文件的内容

时间:2015-04-07 23:02:15

标签: html perl email sendmail mime

我想邮寄另一个脚本的日志文件的内容。我已经尝试了它的工作代码,但是输出不是我预期的。我想要逐行输出,就像在LOG.txt中一样,但是我把它作为一个段落在体内。

my $HOME        ='/apps/stephen/data';
my $FILE        ="$HOME/LOG.txt";
my @HTML        =();

sub copyfile
{
 `$HOME/APPL.ksh > $FILE`;

  push(@HTML,`cat $FILE`);

&sendMail;
}

sub sendMail
{
$sub="TEST";
$from='ABC@ABC.com';
$to='ABC@ABC.com';
    open(MAIL, "|/usr/lib/sendmail -t");
            print MAIL "From: $from \12"; print MAIL "To: $to \12";print    MAIL "Cc: $Cc \12";
            print MAIL "Subject: $sub \12";
            print MAIL "Content-Type: text/html \12";
            print MAIL "Content-Disposition:inline \12";
            print MAIL @HTML;
    close(MAIL);
}

sub init
{
    copyfile;

}
init;

1 个答案:

答案 0 :(得分:3)

添加缺少MIME-Version:标题以完成Content-*:标题。

open(MAIL, "|/usr/lib/sendmail -i -t");
print MAIL << "END";
From: $from
To: $to
Cc: $Cc
Subject: $sub
MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline

END
print MAIL @HTML;
close(MAIL)