使用扩展的 mapi 函数将图像嵌入到 Outlook

发布于 2024-09-12 06:26:04 字数 1266 浏览 10 评论 0原文

我需要在电子邮件中嵌入图像并在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2024-09-19 06:26:04

发问者尚未发布他的 HTML 文本。我怀疑问题是他的 CID url 格式错误 - 但我还没有测试过这一点。

如果 Content-ID 标头设置为:

Content-Type: image/jpeg
Content-Disposition: inline
Content-ID: afd383988e86ad958709@u

那么 HTML 应像这样引用它:

<img width="100" height="100" href="cid:afd383988e86ad958709@u" />

特别是,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:

Content-Type: image/jpeg
Content-Disposition: inline
Content-ID: afd383988e86ad958709@u

Then the HTML should reference it like so:

<img width="100" height="100" href="cid:afd383988e86ad958709@u" />

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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文