附加文件perl的MIME :: Lite错误

时间:2013-05-04 01:43:52

标签: perl email mime

附加文件时出现

500内部服务器错误,但在没有附件的情况下发送时则错误。

    use MIME::Lite; 


$msg = MIME::Lite->new(
    From    =>'email@domain.com',
    To      =>'email@domain2.com',
    Subject =>'A message with 2 parts...',
    CC      => '',
    Type    =>'TEXT',
    Data    =>'Thank you for your interest in'
);

    ### If I comment out the following attachment code the email sends OK, otherwise i get 500 internal server error

$msg->attach(
    Type     =>'image/gif',
    Path     =>'/images/tree.gif',
    Filename =>'tree.gif',
    Disposition => 'attachment'
)or die "error attaching file\n"; 



$msg->send;

2 个答案:

答案 0 :(得分:1)

只是一个建议和一些我可以为此推荐的东西。应用此方法将允许您split包含您的text / html部分和附件,因此您可以根据需要发送包含多个属性的消息。

use strict;
use warnings;

use MIME::Lite; 

my $msg = MIME::Lite->new(
        To      => 'email@domain2.com',
        From    => 'email@domain.com',
        Subject => 'A message with 2 parts...',
        Type    => 'multipart/alternative',
);

# Make my text part
my $txt = MIME::Lite->new(
        Type => "text/plain",
        Data => 'Thank you for your interest in',
);

# Make my html part
my $html = MIME::Lite->new(
         Type => 'multipart/related',
);

# Here you can attach what html tags you would like to include.
$html->attach(
     Type => 'text/html',
     Data => "<b>my html is here</b>",
);

$html->attach(
     Type => 'image/gif',
     Id   => 'tree.gif',
     Path => "../images/tree.gif",
); 

$msg->attach($txt);
$msg->attach($html);

my $data = $msg->as_string;

此外,我看到您使用die进行错误处理的位置,此处无需执行此操作。

答案 1 :(得分:0)

错误的结果是必须相对于脚本编写URI。

所以我不得不改变/images/tree.gif

../images/tree.gif