How to get MIME content of Office365 mail using Microsoft Graph API?

杀马特。学长 韩版系。学妹 提交于 2019-12-08 02:04:52

问题


How to get MIME content of the Office365 mail using Microsoft Graph API so that i can create EML file?

Or is there other way to create EML file of the mail found in Office365 using Microsoft graph API?

I have already tried using EWS API but want to use Graph API.

Thanks in advance


回答1:


There is no support for MIME in Graph or Exchange REST at this time. Use EWS.




回答2:


Microsoft Graph have an API to returning MimeMessage. That is

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

You should replace Id by your message Id. Then read response as stream and then it load to MimeMessage.




回答3:


As per the (Official documentation)

MIME is an industry email standard. Many email applications create messages in MIME format and save them in files with the .EML extension.

Even though Outlook does not save messages in MIME format, there are two ways you can get an Outlook message body in MIME format:

You can append a $value segment to a get-message operation on that message. If the message is attached to an Outlook item or group post, you can append a $value segment to a get-attachment operation on that item or group post.

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

If the message is attached to another message in the user's mailbox:

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

Example

The following is an example that requests a message in the signed-in user's mailbox to be returned with its MIME content.

GET /me/messages/4aade2547798441eab5188a7a2436bc1/$value

The following is the response. The MIME content begins with the MIME-Version header.

        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_--


来源:https://stackoverflow.com/questions/40582626/how-to-get-mime-content-of-office365-mail-using-microsoft-graph-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!