我需要将图像包含到电子邮件正文中(使用 HTML 格式),以便将其嵌入,而不是使用 Perl 中的库 Win32::OLE 调用安装在 Windows 上的 Outlook 客户端的额外附件。
下面的代码有效,但收到的电子邮件不显示图像。我可以看到唯一的一个小方形符号,表示内嵌嵌入图像丢失或损坏。
#use strict;
use warnings;
use Win32::OLE;
#get new Outlook instance
my $mail = new Win32::OLE('Outlook.Application');
die "Unable to start Outlook instance: $!" if !defined $mail;
my $item = $mail->CreateItem(0);
die "Unable to create mail item: $!" if !defined $item;
$item->{'To'} = 'mypersonalgmailaddress@gmail.com';
$item->{'CC'} = '';
$item->{'Subject'} = 'Test for embedded/inline image';
$item->{'BodyFormat'} = 'olFormatHTML';
$item->{'HTMLBody'} = "<html><body><img src=\"signature.png\"></body></html>";
$item->save();
#attach an image and make it embedded.
my $attachments = $item->Attachments();
$attachments->Add('C:\signature.png', olEmbeddeditem);
#send it
$item->Send();
my $error = Win32::OLE->LastError();
print STDERR "Win32::OLE error: $error" if $error;
有人知道上面的代码有什么问题吗?任何建议都将受到高度赞赏。