我需要在电子邮件中嵌入图像并在将电子邮件发送到 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;