我正在尝试在多部分内容电子邮件上附加 pdf 文件,是的,我知道我可以使用 mime lite 或十亿个 perl 模块,但到目前为止,我仅限于使用 perl 5.8.8,因为它是开箱即用的我有
#!/usr/bin/perl
use Net::SMTP;
use MIME::Base64 qw( encode_base64 );
use MIME::Base64 qw( decode_base64 );
use strict;
use warnings;
my $from = 'az@xx.com';
my $to = 'raxxxfael.xx@xxx.com';
my $to2 = 'xx.xx@xxx.com';
my $boundary = 'frontier';
open my $Initial_File, '<', "summary.pdf";
binmode $Initial_File;
open my $Initial_OutFile, '>', "temp.pdf";
my $buf;
while ( read( $Initial_File, $buf, 60 * 57 ) ) {
print $Initial_OutFile encode_base64( $buf );
}
close $Initial_OutFile;
close $Initial_File;
open INFILE, '<', "temp.pdf";
open my $final_output, '>',"summary2.pdf";
binmode $final_output;
my $buffer;
while ( $buffer = <INFILE> ) {
print $final_output decode_base64( $buffer );
}
my @pdf = $final_output;
close $final_output;
close INFILE;
my $smtp = Net::SMTP->new('xx.xxx.com');
$smtp->mail($from);
$smtp->recipient($to,$to2, { SkipBad => 1 });
$smtp->data();
$smtp->datasend("Subject: Test Email \n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: multipart/mixed;\n\tboundary=".$boundary."\n");
$smtp->datasend("\n");
$smtp->datasend("--".$boundary."\n");
$smtp->datasend("Content-type: text/plain\n");
$smtp->datasend("Content-Disposition: quoted-printable\n");
$smtp->datasend("\nTest From You \n");
$smtp->datasend("--".$boundary."\n");
$smtp->datasend("Content-Disposition: attachment; filename=summary2.pdf \n");
$smtp->datasend("Content-Type: application/pdf; name=summary2.pdf ");
$smtp->datasend("\n");
$smtp->datasend("@pdf\n");
$smtp->datasend("--".$boundary."--\n");
$smtp->dataend();
# $smtp->quit;
exit;
电子邮件正确发送,但是(显然)在尝试打开 pdf 文件时说它的编码不正确,有没有办法将 PDF 文件缓冲到附件中,使其按原样发送出去?