我有一个需要更改的遗留应用程序。它是用perl编写的,使用send::mail向用户发送邮件。以前我们在电子邮件正文中发送链接,但现在他们想要pdf附件。PDF是使用php在另一台服务器上生成的。
工作流程将是
- 创建电子邮件正文
- 通过URL从另一台服务器获取pdf
- 将pdf作为附件添加到电子邮件中
- 发送
我想我可以使用
use LWP::Simple;
unless (defined ($content = get $URL)) {
die "could not get $URLn";
}
以获取URL的内容,但我不知道如何在sendmail中使用该var作为附件。当前发送邮件代码为:
my %maildata = (To => $to,
From => 'OurSite - Billing <billing@ourSite.com>',
Organization => 'OurSite, LLC http://www.OurSite.com/',
Bcc => 'sent-billing@ourSite.com',
Subject => $subject{$message} || 'ourSite invoice',
Message => $body
);
print STDERR "notify1 now calling sendmailn";
sendmail(%maildata) || print STDERR $Mail::Sendmail::error;
我遇到的另一个问题是,我不知道如何确定我拥有的sendmail版本(旧的freebsd系统(是否能够发送附件?
好的,感谢海报给了我一些指导/尝试的意愿。
最后,我通过以下构建了mime主体
use LWP::Simple;
use MIME::Base64;
unless (defined ($content = get $URL)) {
die "could not get $URLn";
}
my $pdfencoded = encode_base64($content);
my %maildata = (To => $to,
From => 'OurSite - Billing <billing@ourSite.com>',
Organization => 'OurSite, LLC http://www.OurSite.com/',
Bcc => 'sent-billing@ourSite.com',
Subject => $subject{$message} || 'ourSite invoice',
);
my $boundary = "====" . time() . "====";
$maildata{'content-type'} = "multipart/mixed; boundary="$boundary"";
$maildata{'Message'} = "--".$boundary."n"."Content-Type: text/plainn".$body.
"n--".$boundary."nContent-Transfer-Encoding: base64nContent-Type:
application/pdf; name="invoice.pdf"n".$pdfencoded."n--".$boundary."--";
sendmail(%maildata) || print STDERR $Mail::Sendmail::error;
这给了我一个为正文内容手工构建的MIME格式。
谢谢你的帮助!