使用扩展的 mapi 函数将图像嵌入到 Outlook
我需要在电子邮件中嵌入图像并在 Outlook 中发送之前预览电子邮件。 CDO 和赎回不是一个选择。
我尝试了以下代码,但图像只是显示为一个小块。
procedure AddAttachment(FullFileName: String; Attachments: Outlook2000.Attachments; CID: String);
const
PR_ATTACH_CONTENT_ID = $3712001E;
PR_ATTACH_CONTENT_ID_W = $3712001F; // Unicode
PR_ATTACH_MIME_TAG = $370E001E;
PR_ATTACH_ENCODING = $37020102;
var
IAttach: IMAPIProp;
Prop: PSPropValue;
AAttachment: Outlook2000.Attachment;
FileName: String;
PropValue: TSPropValue;
Prop1: TSPropTagArray;
begin
FileName := ExtractFileName(FullFileName);
Prop := nil;
try
AAttachment := Attachments.Add(FullFileName, olByValue, 1, FileName);
IAttach := AAttachment.MAPIOBJECT as IMAPIProp;
if Assigned(IAttach) then
try
PropValue.ulPropTag := PR_ATTACH_MIME_TAG;
PropValue.Value.lpszA := 'image/jpeg';
HrSetOneProp(IAttach, @PropValue);
PropValue.ulPropTag := PR_ATTACH_CONTENT_ID;
PropValue.Value.lpszA := PAnsiChar(AnsiString(CID));
HrSetOneProp(IAttach, @PropValue);
finally
if Assigned(Prop) then MAPIFreeBuffer(Prop);
IAttach := nil;
end;
except
end;
end;
I need to embed images in an email and preview the email before it is sent in outlook. CDO and Redemption is not an option.
I have tried the following code, but the images just appears as a little block.
procedure AddAttachment(FullFileName: String; Attachments: Outlook2000.Attachments; CID: String);
const
PR_ATTACH_CONTENT_ID = $3712001E;
PR_ATTACH_CONTENT_ID_W = $3712001F; // Unicode
PR_ATTACH_MIME_TAG = $370E001E;
PR_ATTACH_ENCODING = $37020102;
var
IAttach: IMAPIProp;
Prop: PSPropValue;
AAttachment: Outlook2000.Attachment;
FileName: String;
PropValue: TSPropValue;
Prop1: TSPropTagArray;
begin
FileName := ExtractFileName(FullFileName);
Prop := nil;
try
AAttachment := Attachments.Add(FullFileName, olByValue, 1, FileName);
IAttach := AAttachment.MAPIOBJECT as IMAPIProp;
if Assigned(IAttach) then
try
PropValue.ulPropTag := PR_ATTACH_MIME_TAG;
PropValue.Value.lpszA := 'image/jpeg';
HrSetOneProp(IAttach, @PropValue);
PropValue.ulPropTag := PR_ATTACH_CONTENT_ID;
PropValue.Value.lpszA := PAnsiChar(AnsiString(CID));
HrSetOneProp(IAttach, @PropValue);
finally
if Assigned(Prop) then MAPIFreeBuffer(Prop);
IAttach := nil;
end;
except
end;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发问者尚未发布他的 HTML 文本。我怀疑问题是他的 CID url 格式错误 - 但我还没有测试过这一点。
如果 Content-ID 标头设置为:
那么 HTML 应像这样引用它:
特别是,cid URL 必须具有前缀“cid:”,但 content-id 标头不能。 (guid 对于 content-id 来说是一个不错的选择,只不过它必须包含
@
符号。为了符合要求,您可以将“@u”附加到 guid 后面。)这就足以让电子邮件在接收端正确显示。我不知道发送前是否可以在 Outlook 中正确预览。
您可能还希望看到这个问题:
Questioner hasn't posted his HTML text. I suspect the problem is that his CID urls were malformed - hwoever I have not tested this.
If the Content-ID header is set to this:
Then the HTML should reference it like so:
In particular, the cid URL must have the prefix "cid:" but the content-id header must not. (A guid is a good choice for a content-id, except that it MUST contain an
@
symbol. To comply, you can append '@u' to the guid.)That is sufficent to have the email display correctly at the receiving end. Whether it will make it preview in outlook correctly before sending, I don't know.
You may wish to also see this question: