image - Perl - Outlook - 将嵌入图像包含在电子邮件正文中(HTML)
问题描述
我需要将图像包含到电子邮件正文中(使用 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;
有人知道上面的代码有什么问题吗?任何建议都将受到高度赞赏。
解决方案
您需要附加图像,然后设置可以在消息正文中使用的 CID:
Attachment attachment = newMail.Attachments.Add(@"E:\Pictures\image001.jpg"
, OlAttachmentType.olEmbeddeditem , null , "Some image display name" );
string imageCid = "image001.jpg@123";
attachment.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageCid);
newMail.HTMLBody = String.Format("<body><img src=\"cid:{0}\"></body>", imageCid );
推荐阅读
- apache-spark - GKE 上的 Dataproc 在提交作业时不使用图像
- java - 这个java代码中的全局变量没有改变,但我正在改变它
- c++ - 与 dll 共享静态库内存
- android - 无法在 Flutter 中使用 Firebase Auth 进行注册
- python - 我想知道为什么我的搜索电话簿功能无法正常工作
- algorithm - 使用段阻塞查找两点之间的最短距离
- r - R purrr,我可以在 modify_if 语句中使用两个数组吗?
- go - 如何设置私有仓库的 go 模块路径
- ios - 通过 Sublayer 改变 UIView 的渐变背景
- node.js - 如何在此节点服务器上启用 cors