如何发送带有嵌入式附件的电子邮件 [英] How do I send Email with inline Attachments

查看:355
本文介绍了如何发送带有嵌入式附件的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发送团队与Office API 365进行json集成的描述.

I send the description my team is having with the json integration with Office API 365.

我们想通过JSON API发送带有内联附件的电子邮件.

We want to send an email with inline attachments through the JSON API.

出于这个目标,我们正在做什么:

With that objective, what we are doing:

  1. 使用回复操作创建一个空的草稿消息;
  2. 发送几个内联附件;
  3. 更新消息草稿的正文(内嵌cid图片);
  4. 发送消息;

我们的API有什么问题?

What is our issue with the API?

当我们将附件提交到Office API 365时,我们无法设置"ContentType"属性. 尽管我们发送了"ContentType",但它始终为空.

We are unable to set the "ContentType" properties when we submit the attachments to the Office API 365. Despite the "ContentType" we send, it is always null.

我们正在使用以下API:POST https://outlook.office365 .com/api/v1.0/me/messages/ {message_id}/附件

We are using the following API: POST https://outlook.office365.com/api/v1.0/me/messages/{message_id}/attachments

这就是我们认为尽管在正文中找到了嵌入式图像,但由于内容类型设置不正确而无法显示的原因.

That's the reason we think that despite the inline image then it is found in the body, it cannot be displayed because the contenttype it is not set correctly.

请给我们一些指导.

推荐答案

ContentType不应成为问题.重要的是将ContentId属性设置为一个值,然后在邮件正文中的cid链接中使用该值.这是对我有用的东西:

The ContentType shouldn't be an issue. What is important is that you set the ContentId property to a value, then use that value in your cid link in the message body. Here's what worked for me:

POST /Me/folders/drafts/messages

{
  "Subject": "Inline image test",
  "Body": {
    "ContentType": "HTML",
    "Content": "<html><body><strong>There should be an image here:</strong><p><img src=\"cid:my_inline_attachment\"></p></body></html>"
  }
}

注意cid:my_inline_attachment位.

然后做:

POST /Me/messages({message_id})/Attachments

{
  "@odata.type": "#Microsoft.OutlookServices.FileAttachment",
  "Name": "th.jpg",
  "IsInline": true,
  "ContentId": "my_inline_attachment",
  "ContentBytes": {base64-encoded contents of jpeg}
}

请注意附件JSON中的"ContentId": "my_inline_attachment"行.希望有帮助!

Notice the "ContentId": "my_inline_attachment" line in the attachment JSON. Hope that helps!

这篇关于如何发送带有嵌入式附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆