我正在尝试发送带有内嵌图像的 HTML 电子邮件。我将不得不使用本机 unix 的东西,Email::Mime
因为这些是我发现安装在我坚持的盒子里的唯一东西。我正在创建一条Email::Mime
消息并将其发送到sendmail
. 我正在使用cid
内联图像,但由于某种原因,我一直将图像作为附件。
有人可以帮助我,代码片段如下。
sub send_mail(){
use MIME::QuotedPrint;
use HTML::Entities;
use IO::All;
use Email::MIME;
$boundary = "====" . time() . "====";
$text = "HTML mail demo\n\n"
. "This is the message text\n"
. "Voilà du texte qui sera encodé\n";
$plain = encode_qp $text;
$html = encode_entities($text);
$html =~ s/\n\n/\n\n<p>/g;
$html =~ s/\n/<br>\n/g;
$html = "<p><strong>" . $html . "</strong></p>";
$html .= '<p><img src="cid:123.png" class = "mail" alt="img-mail" /></p>';
# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/html",
encoding => "quoted-printable",
charset => "US-ASCII",
},
body_str => "<html> $html </html>",
),
Email::MIME->create(
attributes => {
content_type => "image/png",
name => "pie.png",
disposition => "Inline",
charset => "US-ASCII",
encoding => "base64",
filename => "pie.png",
"Content-ID" => "<123.png>",
path => "/local_vol1_nobackup/user/ramondal/gfxip_gfx10p2_main_tree03/src/verif/ge/tb",
},
body => io("pie.png")->binary->all,
),
);
my $email = Email::MIME->create(
header_str => [
To => 'abc@xyz.com',
Subject => "Test Email",
],
parts => [@parts],
);
# die $email->as_string;
open(MAIL, "|/usr/sbin/sendmail -t") or die $!;
print MAIL $email->as_string;
close (MAIL);
}