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

问题描述 投票:0回答:3

我想在.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?

javascript outlook exchangewebservices outlook-addin office-addins
3个回答
4
投票

没有MSG格式是Office文件格式(复合文件格式https://en.wikipedia.org/wiki/Compound_File_Binary_Format,这不是很容易生成)所以通常使用Outlook或Redemption是唯一可行的方法,以及人们通常尝试使用MSG格式的唯一真正原因是保持MAPI属性和附件类型的保真度,您将需要MAPI。

对于您使用EWS所做的事情,您使用IncludeMimeContent返回的内容是Message的MIMEConent,它可以保存为EML文件,因此可以在任何支持EML的电子邮件客户端中打开,包括Outlook,这通常足以满足大多数事情(不包括移民)。


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)


0
投票

它是测试版,没有文档,但您可以使用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,将版本设置为测试版。 然后,您可以将响应保存为.eml文件。

编辑:

现在它正式预览:https://docs.microsoft.com/en-us/graph/outlook-get-mime-message

© www.soinside.com 2019 - 2024. All rights reserved.