perl Email :: MIME无法正常工作

时间:2015-02-25 22:57:01

标签: perl email

以下代码有时会起作用,有时则不行。它在linux上运行,安装了postfix,我禁用它并停止了服务。这需要postfix来运行吗?

当我在终端中运行此测试代码时,我没有收到任何错误,没有电子邮件。

    #!/usr/bin/perl
    use warnings;
    use strict;
    use Data::Dumper;
    use Email::MIME;
    use Email::Sender::Simple qw(sendmail);

        my $sub='test';
        my $exitCode=0;
        my $emailTo='raxxxx@xxxx.com';
        my $bcc='';

        if ($exitCode == 0){$exitCode = '';}

        my @mesgBody = ("test\n","email\n");
        my $message = Email::MIME->create(
              header_str => [
                From    => '"Rajeev" <'.$emailTo.'>',
                To      => $emailTo,
                Subject => $sub,
              ],
              attributes => {
                'X-Priority' => 1,
                'X-MSMail-Priority' => 'High',
                encoding => 'quoted-printable',
                charset  => 'ISO-8859-1',
              },
              body_str => "@mesgBody"."\n".$exitCode,   #old   body_str => $sub."\n".$mesg."\n".$exitCode,
            );

        #sendmail($message);
        if ($bcc eq ''){
            my $result=sendmail(
                $message,
                {
                    from => '"Rajeev" <'.$emailTo.'>',
                    to   => [$emailTo],
                }
            );
print "result=".Dumper($result)."\n";
        } else {
            sendmail(
                $message,
                {
                    from => '"Rajeev" <'.$emailTo.'>',
                    to   => [$emailTo, $bcc],
                }
            );
        }

输出: - &GT; result = $ VAR1 = bless({},&#39; Email :: Sender :: Success&#39;);

所以,如果这是成功的,为什么我没有收到任何电子邮件?

我还在系统日志中看到 nothing

谢谢。

1 个答案:

答案 0 :(得分:0)

# service postfix start

解决了这个问题。