【发布时间】:2019-05-05 03:55:34
【问题描述】:
我正在尝试发送带有内嵌图像的 HTML 电子邮件。我将不得不使用本机 unix 的东西和Email::Mime,因为这些是我发现安装在我坚持使用的盒子中的唯一东西。我正在创建一个Email::Mime 消息并将其发送到sendmail。我正在使用cid 内嵌图像,但由于某种原因,我一直将图像作为附件获取。
谁能帮帮我,下面是代码sn-p。
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);
}
【问题讨论】:
-
也许可以试试embedding 图片?
-
根据stackoverflow.com/questions/4018709/…你可以试试
<123.png@mymail>?