我已按照Email::Sender和Email::MIME中的示例进行操作,它看起来不错,直到您尝试打开 PDF。然后很明显,它的大小比原来的小,而且不知何故损坏了。我的脚本或多或少是为测试目的而给出的示例的模板副本,但我担心 MIME 的东西在这里不起作用。
use strict;
use warnings;
use Data::Dumper;
use IO::All ;
use Email::Simple;
use Email::Simple::Creator;
use Email::MIME;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP;
# assemble the parts
my @parts = (
Email::MIME->create(
attributes => {
filename => "report.pdf",
content_type => "application/pdf",
encoding => "quoted-printable",
name => "report.pdf",
},
body => io("report.pdf")->all
),
Email::MIME->create(
attributes => {
content_type => "text/plain",
disposition => "attachment",
charset => "US-ASCII",
},
body => "Hello there!",
),
);
# assemble parts into email
my $email = Email::MIME->create(
header => [
To => 'me@you.com',
From => 'me@you..com',
Subject => "Thanks for all the fish ...",
],
parts => [@parts],
);
# standard modifications
$email->header_set( 'X-PoweredBy' => 'RT v3.0' );
# more advanced
# $_->encoding_set('base64') for $email->parts;
# send the email
my $transport = Email::Sender::Transport::SMTP->new({
host => 'mail.whatever.com',
# port => 2525,
sasl_username => 'webuser',
sasl_password => 's3cr3t',
timeout => 20,
});
sendmail( $email, { transport => $transport } );
我正在使用 Windows 和 Perl 5.12.1.0。它似乎不是IO::All模块,但我认为问题出在此处。有没有人足够了解这些东西来帮助我修复它?
我尝试过二进制模式、不同的 SMTP 服务器、不同的 PDF 文件,但我根本无法让这该死的东西正常工作。