【问题标题】:How to get the email content as EML or MSG from the exchange server using JavaScript?如何使用 JavaScript 从交换服务器获取电子邮件内容为 EML 或 MSG?
【发布时间】:2019-02-01 17:38:19
【问题描述】:

我想在我的Node 应用程序中获取.msg 格式的电子邮件内容。目前,我发送以下 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


【解决方案1】:

不,MSG 格式是 Office 文件格式(复合文件格式 https://en.wikipedia.org/wiki/Compound_File_Binary_Format,生成起来并不简单),因此通常使用 Outlook 或 Redemption 是唯一实用的方法,也是人们通常尝试这样做的唯一真正原因使用 MSG 格式是为了保持您需要 MAPI 的 MAPI 属性和附件类型的保真度。

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

【讨论】:

    【解决方案2】:

    正如 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)

    【讨论】:

    • 嗨@mikel,我能够获得带有附件的单个邮件数据,但是,我仍然对“转换部分”感到困惑。如何将 API 响应转换为 .eml 文件??
    • 然后您可以生成包含从中获得的所有数据的 .eml 文件。这是一个邮件如何看起来像 .eml phpclasses.org/browse/file/14672.html 的示例。你可以使用 rfc1521 ietf.org/rfc/rfc1521.txt
    【解决方案3】:

    它处于测试阶段,没有文档,但您可以使用 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 2016-05-24
      • 2014-03-21
      • 1970-01-01
      • 2013-05-25
      • 2022-12-28
      • 1970-01-01
      相关资源
      最近更新 更多