About: EWS/REST/Graph and MSG files


EWS, REST and Graph can save and load MSG file attachments to items such as email. However, they cannot create, update or parse .MSG files.  These APIs are Exchange based and don't know about and have never supported creating, loading or parsing MSG files.  MSG files are Outlook data storage files and only Extended MAPI and Outlook Object Model (OOM) APIs are supported with them.  Both OOM and MAPI need Outlook to be installed.  OOM is an automation API for Outlook, which is a user desktop application and needs to have a user present when its automation API (OOM) is used.  Extended MAPI is a messaging sub-system which is installed with Outlook – so Outlooked must be installed on the machine where MAPI is used.

Outlook's MSG files are not in full fidelity (i.e. having full properties of items) and neither is .EML (email MIME). If you wanted to do something like move items from one mailbox to another then you could use EWS to extract an email as a blob (EWS ExportItems) and load it on another mailbox for review (EWSUploadItems).  A document review system could store such a blob for later import into a mailbox and also contain items properties to be displayed to a user for review.  The format for these blobs is not documented, so there is no support for parsing them with custom code   However, it's very important to understand that these blobs contain the full fidelity of properties for an item – this is something unique to EWS at this point; however, keep an eye on REST and Graph in this type of feature gets added in the future (I have no info on if or if not it will be added).

Note that EWS has a special method which can convert between EWS IDs, IDs of MAPI and Outlook.  This means you can mix EWS/MAPI/OOM API to some extent. For all APIs you should be able to use the StoreId of items between the different APIs.  One common mix is to use them in a custom add-in in Outlook.

If you are thinking of using the old Exchange MAPI: There were once two MAPIs… Long ago there was a version of Extended MAPI which was part of Exchange and could be downloaded – however, we have not supported that version of MAPI for a very long time.  This download was created due to customers wanting to use it on Exchange 2007.  See, earlier versions of Exchange installed Extended MAPI and those versions of Exchange used it.  Exchange 2007 was a huge rewrite of Exchange and a lot of its existing code was replaced and it was no longer MAPI based.  MAPI was removed as an installed API also.  Some customers had MAPI applications they wanted to use on their Exchange server, so the Exchange product team created the Exchange MAPI download as a stop-gap API to give customers a chance to update their code to use the newer APIs (EWS and PowerShell).  The Exchange download version of MAPI is no longer supported. So, in the end you will need to have Outlook installed to work with MSG files. Also note that OOM is only supported in a user session where a user can interact with dialogs which might be displayed – it's not supported in a background session which would include apps like page, windows services or web services.

EWS:

Here are the EWS calls which can save and load items using EWS:

               How to: Export items by using EWS in Exchange
               https://msdn.microsoft.com/en-us/library/office/dn672317(v=exchg.150).aspx

               How to: Import items by using EWS in Exchange
               https://msdn.microsoft.com/en-us/library/office/dn672319(v=exchg.150).aspx

Custom code:

MSG files can be created programmatically using one of our APIs or through custom code.  The custom code approach is not supported.  You could write custom code to create an MSG file, using data you extracted separately from an item using EWS.  However, there is no developer support for creating an MSG file in this manner.

[MS-OXMSG]: Outlook Item (.msg) File Format
https://msdn.microsoft.com/en-us/library/cc463912(v=exchg.80).aspx

.MSG File Format (Part 1)
https://blogs.msdn.microsoft.com/openspecification/2009/11/06/msg-file-format-part-1/

OOM and MAPI:

It's better to use Outlook Object Model (OOM) or Extended MAPI to create an .MSG file.  OOM code needs to be run with a user present who can respond to dialogs – it's not supported in a background process.  OOM can be used with .Net language, unmanaged languages such as C+ and also by scripting languages.  Extended MAPI code needs to be used in unmanaged code – such as C++; it's not supported under .NET.  Both APIs are only supported on a machine where Outlook is installed because they require Outlook to be installed (MAPI needs Outlook's MAPI subsystem and OOM needs Outlook).

About: Outlook Object Model (OOM)
http://blogs.msdn.com/b/webdav_101/archive/2015/05/18/about-outlook-object-model-oom.aspx

About: Extended MAPI
http://blogs.msdn.com/b/webdav_101/archive/2015/05/18/about-extended-mapi.aspx

OOM can save and load items to file as MSG:

Looking for a way to save a .msg file or load a .msg file?
https://blogs.msdn.microsoft.com/webdav_101/2007/05/04/looking-for-a-way-to-save-a-msg-file-or-load-a-msg-file

OlSaveAsType Enumeration (Outlook)
https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/olsaveastype-enumeration-outlook

MAPI to MIME conversion API:

With unmanaged code (C++, etc.) on a machine having Outlook installed you can use the MAPI to MIME Conversion API.  This API can import an MSG into Outlook or export and email to an MSG file.

About the MAPI-MIME Conversion API
https://msdn.microsoft.com/en-us/library/office/ff960635.aspx

Unicode MSG Files
https://blogs.msdn.microsoft.com/stephen_griffin/2006/05/25/unicode-msg-files

No MSG For You!
https://blogs.msdn.microsoft.com/stephen_griffin/2008/01/08/no-msg-for-you

IConverterSession : IUnknown
https://msdn.microsoft.com/en-us/library/ff960231.aspx

Note: If you export to EML then covert to an MSG file you will have roughly the same data in the MSG file.

Third Party APIs which work with MSG files:

If you are considering a third-party API then please understand that those would need to be provided by the vendor who created them.

Working with attachments – EWS:

How to extract exchange attachments using Exchange Web Services and VB.NET
https://www.codeproject.com/articles/504705/how-to-extract-exchange-attachments-using-exchange

Attachments and EWS in Exchange
https://msdn.microsoft.com/en-us/library/office/dn726693(v=exchg.150).aspx

Getting attachments by using the EWS Managed API 2.0
https://msdn.microsoft.com/en-us/library/office/dd633665(v=exchg.80).aspx

Working with attachments by using the EWS Managed API 2.0
https://msdn.microsoft.com/en-us/library/office/dd633616(v=exchg.80).aspx

Working with attachments – Graph:

    Attachment resource type
    https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/attachment

Working with attachments – REST:

Outlook Mail REST API reference
https://msdn.microsoft.com/en-us/office/office365/api/mail-rest-operations

 


Comments (0)

Skip to main content