我正在使用Email::MIME
从Perl脚本发送邮件。所有邮件都很顺利。但事情是,当我给出多个密件抄送邮件ID时,对于密件抄送地址邮件不发送。它不会抛出任何错误。
在这种情况下,任何人都可以提供帮助吗?
use Encode;
use Email::Sender::Simple qw/try_to_sendmail/;
use Email::MIME;
use Email::Sender::Transport::SMTP::TLS;
use Email::Address::XS;
my $mailinfo = shift;
my $username = usename;
my $password = password;
my $from = fromaddress;
my $to = to;
my $subject = subject;
my $body = body;
my $host = host;
my $port = port;
my $bcc = bcc;
my $email = Email::MIME->create(
header_str => [
From => Email::Address::XS->new($display_name,$from),
To => $to,
Subject => Encode::encode('MIME-Header-ISO_2022_JP', $subject),
],
parts => [ @body1 ],
);
$_->encoding_set( 'base64' ) for $email->parts;
try_to_sendmail(
$email,
{
to => [$to,$bcc],
transport => Email::Sender::Transport::SMTP::TLS->new(
host => $host,
port => $port,
username => $username,
password => $password,
)
}
) or do {
print "Error occured while mail send\n";
}
答案 0 :(得分:1)
创建消息Email::MIME->create
时,请勿添加BCC标头。
您在to
中发送到的有效地不在标题中的任何地址都是密件抄送地址。
my $email = Email::MIME->create(
header_str => [
From => Email::Address::XS->new($display_name,$from),
To => [$to, $bcc]
Subject => Encode::encode('MIME-Header-ISO_2022_JP', $subject),
],
parts => [ @body1 ],
);
编辑:根据您在密件抄送中的多个地址的问题。
你应该把它作为:
$bcc1 = 'john@doe.com';
$bcc2 = 'sam@ibm.com';
$bcc3 = 'dennis@dell.com';
然后将其作为
发送To => [$to, $bcc1, $bcc2, $bcc3]
或定义一串电子邮件地址加入并发送,如下所示。
@bcc = ('john@doe.com', 'sam@ibm.com', 'dennis@dell.com');
To => join (',', @bcc),
或者您可以将$ bcc定义为字符串
$bcc = 'john@doe.com, sam@ibm.com, dennis@dell.com';
To => [$to, $bcc]
您需要使用逗号而不是空格来分隔电子邮件地址。