0

我已经使用此脚本发送文本文件,电子邮件带有附件,但是当我打开附件时它是空白的。知道为什么吗?我错过了什么吗?谢谢

#!/usr/bin/perl -wl
my $msg = MIME::Lite->new(
    From    => 'xxx.net',
    To      => 'xxx.com',
    Subject => 'Report',
    Type    => 'multipart/mixed',
)or die "Error creating multipart container: $!\n";
$msg->attach(
    Type     => 'TEXT',
    Data     => " Please check the attached file.",
)or die "Error adding the text message part: $!\n";
$msg->attach (
   Type => 'text/plain',
   Path => '/myfile/file1',
   Filename => 'result.txt',
   Disposition => 'attachment'
)or die "Error adding the attached file part: $!\n" ;
$msg->send;
4

1 回答 1

3

您对attach. 来自精美手册

文件名
可选。附件的名称。您可以使用它为将附件保存到磁盘的最终用户提供推荐的文件名。如果“路径”末尾的文件名不合适,或者您使用的是“数据”而不是“路径”,则仅需要此选项。您不应在此处输入路径信息(例如,不应使用“/”或“\”或“:”字符)。

[...]


“数据”或“FH”的替代路径。包含数据的文件的路径...实际上,它可以是任何可打开()的表达式。如果它看起来像一个路径,最后一个元素将自动被视为文件名。另请参阅“立即阅读”。

Path是您要附加的文件的完整路径,是Filename您希望接收者查看该文件的名称。

我想你想要这个:

$msg->attach (
   Type => 'text/plain',
   Path => '/myfile/file1/result.txt',
   Filename => 'result.txt',
   Disposition => 'attachment'
) or die "Error adding the attached file part: $!\n" ;
于 2011-05-25T21:45:01.853 回答