如何使用JavaScript从交换服务器获取EML或MSG电子邮件内容?

时间:2018-08-27 07:58:44

标签: javascript outlook exchangewebservices outlook-addin office-addins

我想在.msg应用程序中以Node格式获取电子邮件的内容。目前,我发送以下SOAP请求以获取电子邮件的html版本:

const getEmailContentSOAP = `<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
    <soap:Header>
        <RequestServerVersion Version="Exchange2013"
          xmlns="http://schemas.microsoft.com/exchange/services/2006/types"
          soap:mustUnderstand="0" />
      </soap:Header>
  <soap:Body>
    <GetItem
      xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
      xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
      <ItemShape>
        <t:BaseShape>Default</t:BaseShape>
        <t:IncludeMimeContent>true</t:IncludeMimeContent>
      </ItemShape>
      <ItemIds>
        <t:ItemId Id="${emailID}" />
      </ItemIds>
    </GetItem>
  </soap:Body>
</soap:Envelope>`;

是否可以直接获取.msg版本或将其转换为.msg?

3 个答案:

答案 0 :(得分:4)

没有MSG格式是Office文件格式(复合文件格式https://en.wikipedia.org/wiki/Compound_File_Binary_Format,这不是微不足道的),因此通常使用Outlook或Redemption是唯一可行的方法,同时也是人们通常会遇到的唯一真正原因尝试使用MSG格式是为了维护您需要MAPI的MAPI属性和附件类型的保真度。

对于使用EWS所做的操作,使用IncludeMimeContent返回的内容是消息的MIMEConent,可以将其保存为EML文件,从而在支持EML的任何电子邮件客户端(包括Outlook)中打开,这通常足以满足大多数情况事物(不包括迁移)。

答案 1 :(得分:1)

正如Glen所说,生成EML格式的电子邮件。我已经做到了,它可以与其他邮件客户端配合使用(SharePoint还具有.eml文件的预览模式!)。

我建议您使用Microsoft Graph API获取所有邮件数据,以便生成.eml邮件。

使用附件获取单个邮件数据的API调用示例:

`https://graph.microsoft.com/v1.0/me/messages/${messageId}?$expand=attachments`

然后将其转换。

您可以通过以下网址获取更多数据:

MSGraph Message docs

MSGraph Message attachments docs

MSGraph quick starts (includes node and angular)

答案 2 :(得分:0)

它处于beta版本,没有文档,但是您可以使用Microsoft Graph API获得MIME内容:

GET https://graph.microsoft.com/beta/me/messages/{id}/$value

GET https://graph.microsoft.com/beta/users/{id | userPrincipalName}/messages/{id}/$value

您可以尝试使用Graph Explorer,将版本设置为beta。
然后,您可以将响应另存为.eml文件。

相关问题