excel - 使用 MIME::Lite 将 xlsx 附加到电子邮件

标签 excel perl mime-types

我正在尝试使用 Excel::Writer::XLSX 发送一封带有 xlsx 文件附件的电子邮件和 MIME::Lite 。 Excel 文件的生成工作正常,因为我可以 scp 并在 Excel 中打开该文件,没有任何问题。当我尝试从电子邮件客户端 (Outlook 2013) 打开附件时,出现此错误:

"Excel cannot open the file "from_2014-06_to_2014-07.xlsx" because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

outlook显示的文件大小是444B,但实际上是95K。我一直在使用 Spreadsheet::WriteExcel 发送 xls 文件并且 mime 类型“application/vnd.ms-excel”之前没有任何问题。

这是我尝试发送电子邮件的内容:

sub send_mail{
    my $filename = shift;
    my $to_email = shift;
    my $from_email = shift;
    my $date = shift;
    $filename = shift;

    my $mail = MIME::Lite->new(
        'From'          => '$from_email',
        'To'            => $to_email,
        'Subject'       => "Radio/TV stats $date",
        'Type'          => 'multipart/mixed',
        #'content-type'  => 'application/zip',
        #'Data'       => "Here is your stuff",
    );

    $mail->attach(
        'Type'          => 'TEXT',
        'Data'          => "Here is your stuff",
    );

    $mail->attach(
        #'Type'          => 'application/vnd.ms-excel',
        'Type'          => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'Path'          => $filepath,
        'Filename'      => $filename,
        'Disposition'   => 'attachement',
    );

    $mail->send('sendmail');
}

任何人都可以帮我附加 xlsx 文件吗?

最佳答案

shift两次到$filename(第二个和第六个字符串),并且变量$filepath未声明。这里可能有错误吗?

关于excel - 使用 MIME::Lite 将 xlsx 附加到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24504635/

相关文章:

javascript - Angular 应用程序中的 Google MAP API key

css - 如何将内联 CSS 样式添加到 Gmail 电子邮件 (SES sendRawEmail)?

excel - CSV 文件创建,如 unicodetext、endig .csv。 VBA 无法打开、保存和关闭更改

excel - 个人宏不起作用: Selecting range and pasting into body of Outlook email

Perl 写入文件流导致意外的 SIGPIPE 错误

Perl复制命令等待复制完成

python - 由于 : file does not start with RIFF id,无法将文件 file.wav 作为 WAV 打开

VBA-回车

c# - 错误外部表不是预期的格式

perl - 我如何确定连接在 mod_perl 中使用的是哪个 SSL 客户端证书?