发送的电子邮件中的附件为空白

发布于 2024-11-09 17:45:35 字数 676 浏览 0 评论 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;

I have used this script to send the text file, the email go out with attachment but when I open the attached file it's blank. any idea why? did I miss anything. thx

#!/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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩世 2024-11-16 17:45:35

您对 attach 的参数有点困惑。来自精细手册

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

[...]

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

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" ;

You're a little confused about the arguments to attach. From the fine manual:

Filename
Optional. The name of the attachment. You can use this to supply a recommended filename for the end-user who is saving the attachment to disk. You only need this if the filename at the end of the "Path" is inadequate, or if you're using "Data" instead of "Path". You should not put path information in here (e.g., no "/" or "\" or ":" characters should be used).

[...]

Path
Alternative to "Data" or "FH". Path to a file containing the data... actually, it can be any open()able expression. If it looks like a path, the last element will automatically be treated as the filename. See "ReadNow" also.

The Path is the full path to the file that you want to attach, the Filename is the name that you want to receiver to see for that file.

I think you want this:

$msg->attach (
   Type => 'text/plain',
   Path => '/myfile/file1/result.txt',
   Filename => 'result.txt',
   Disposition => 'attachment'
) or die "Error adding the attached file part: $!\n" ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文