我正在尝试使用 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/