【问题标题】:How to get MIME content of Office365 mail using Microsoft Graph API?如何使用 Microsoft Graph API 获取 Office365 邮件的 MIME 内容?
【发布时间】:2019-10-31 13:40:44
【问题描述】:

如何使用 Microsoft Graph API 获取 Office365 邮件的 MIME 内容,以便创建 EML 文件?

或者有没有其他方法可以使用 Microsoft graph API 创建 Office365 中找到的邮件的 EML 文件?

我已经尝试过使用 EWS API 但想使用 Graph API。

提前致谢

【问题讨论】:

    标签: office365 microsoft-graph-api eml


    【解决方案1】:

    目前不支持 Graph 或 Exchange REST 中的 MIME。使用 EWS。

    【讨论】:

      【解决方案2】:

      Microsoft Graph 具有返回 MimeMessage 的 API。那是

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

      您应该将 Id 替换为您的消息 ID。然后将响应作为流读取,然后将其加载到 MimeMessage。

      【讨论】:

      【解决方案3】:

      根据 (Official documentation)

      MIME 是行业电子邮件标准。许多电子邮件应用程序以 MIME 格式创建消息并将它们保存在扩展名为 .EML 的文件中。

      即使 Outlook 不以 MIME 格式保存邮件,也有两种方法可以获取 MIME 格式的 Outlook 邮件正文:

      您可以将$value 段附加到对其进行的get-message 操作 信息。如果邮件附加到 Outlook 项目或组帖子, 您可以将 $value 段附加到其上的 get-attachment 操作 项目或小组帖子。

      GET /users/{id}/messages/{id}/$value
      

      如果邮件附加到用户邮箱中的另一封邮件:

      GET /users/{id}/messages/{id}/attachments/{id}/$value
      

      示例

      以下示例请求将登录用户邮箱中的邮件连同其 MIME 内容一起返回。

      GET /me/messages/4aade2547798441eab5188a7a2436bc1/$value
      

      以下是回复。 MIME 内容以 MIME-Version 标头开头。

              Received: from contoso.com (10.194.241.197) by 
          contoso.com (10.194.241.197) with Microsoft 
          SMTP Server (version=TLS1_2, 
          cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1374.0 via Mailbox 
          Transport; Mon, 4 Sep 2017 03:00:08 -0700 
          Received: from contoso.com (10.194.241.197) by 
          contoso.com (10.194.241.197) with Microsoft 
          SMTP Server (version=TLS1_2, 
          cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.1374.0; Mon, 4 Sep 
          2017 03:00:07 -0700 
          Received: from contoso.com 
          (fe80::5bf:5059:4ca0:5017) by contoso.com 
          (fe80::5bf:5059:4ca0:5017%12) with mapi id 15.01.1374.000; Mon, 4 Sep 2017 
          03:00:01 -0700 
          From: Administrator <admin@contoso.com> 
          To: Administrator <admin@contoso.com> 
          Subject: This email has attachment. 
          Thread-Topic: This email has attachment. 
          Thread-Index: AQHTJWSHSywMzSz8o0OJud48nG50GQ== 
          Date: Mon, 4 Sep 2017 10:00:00 +0000 
          Message-ID: 
                          <4aade2547798441eab5188a7a2436bc1@contoso.com> 
          Accept-Language: en-US 
          Content-Language: en-US 
          X-MS-Exchange-Organization-AuthAs: Internal 
          X-MS-Exchange-Organization-AuthMechanism: 04 
          X-MS-Exchange-Organization-AuthSource: 
                          contoso.com 
          X-MS-Has-Attach: yes 
          X-MS-Exchange-Organization-Network-Message-Id: 
                          0ffdb402-ec03-42c8-5d32-08d4f37bb517 
          X-MS-Exchange-Organization-SCL: -1 
          X-MS-TNEF-Correlator: 
          X-MS-Exchange-Organization-RecordReviewCfmType: 0 
          x-ms-publictraffictype: Emai
      
          ```http
          MIME-Version: 1.0 
          Content-Type: multipart/mixed; 
                          boundary="_004_4aade2547798441eab5188a7a2436bc1contoso_" 
      
          --_004_4aade2547798441eab5188a7a2436bc1contoso_ 
          Content-Type: multipart/alternative; 
                          boundary="_000_4aade2547798441eab5188a7a2436bc1contoso_" 
      
          --_000_4aade2547798441eab5188a7a2436bc1contoso_ 
          Content-Type: text/plain; charset="iso-8859-1" 
          Content-Transfer-Encoding: quoted-printable 
      
          The attachment is an email. 
      
          --_000_4aade2547798441eab5188a7a2436bc1contoso_ 
          Content-Type: text/html; charset="iso-8859-1" 
          Content-Transfer-Encoding: quoted-printable 
      
          <html> 
          <head> 
          <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 
          1"> 
          <style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= 
          n-bottom:0;} --></style> 
          </head> 
          <body dir=3D"ltr"> 
          <div id=3D"divtagdefaultwrapper" style=3D"font-size:12pt;color:#000000;font= 
          -family:Calibri,Helvetica,sans-serif;" dir=3D"ltr"> 
          <p>The attachment is an email.</p> 
          </div> 
          </body> 
          </html> 
      
          --_000_4aade2547798441eab5188a7a2436bc1contoso_-- 
      
          --_004_4aade2547798441eab5188a7a2436bc1contoso_ 
          Content-Type: application/octet-stream; name="Attachment email.eml" 
          Content-Description: Attachment email.eml 
          Content-Disposition: attachment; filename="Attachment email.eml"; size=408; 
                          creation-date="Mon, 04 Sep 2017 09:59:43 GMT"; 
                          modification-date="Mon, 04 Sep 2017 09:59:43 GMT" 
          Content-Transfer-Encoding: base64 
      
          RnJvbToJQWRtaW5pc3RyYXRvciA8YWRtaW5AdGVuYW50LUVYSEItMTQ3MS5jb20+DQpTZW50OglN 
          b25kYXksIFNlcHRlbWJlciA0LCAyMDE3IDM6MjYgUE0NClRvOglTcml2YXJkaGFuIEhlYmJhcg0K 
          U3ViamVjdDoJQXR0YWNobWVudCBlbWFpbA0KDQpJIHdpbGwgYXR0YWNoIHRoaXMgZW1haWwgdG8g 
          YW5vdGhlciBtYWlsLg0K 
      
          --_004_4aade2547798441eab5188a7a2436bc1contoso_--
      

      【讨论】:

        猜你喜欢
        • 2023-01-29
        • 2021-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多