none
How to Save Outlook email as .eml file using add-in when it was in compose mode RRS feed

  • Question

  • I am developing an outlook add-in which should allow user to save the outlook email which is in compose mode as a .eml file and save it to Google Drive/Dropbox before sending. I was able to get the message body, cc, to, subject etc but unable to get the attachment. Is there a way I can get all the details of the Item including attachment using ItemId and save it as .eml file?
    In compose mode on clicking send button I managed to get ItemId and using it the rest of the message data.
    Tuesday, October 9, 2018 9:22 AM

All replies

  • Hi Jackson,

    You can either import the messages into Outlook Express and save them as EML files.

    Or you can use Redemption and its RDOMail.SaveAs or SafeMailItem.SaveAs methods - it can save in the MIME format (olRfc822) along with a dozen or so other formats.

    It uses IConverterSession object when it is available (Outlook 2003 and up) or its own converter for an older version of Outlook or when used against the Exchange version of MAPI.

      set Session = CreateObject("Redemption.RDOSession")
      Session.MAPIOBJECT = Application.Session.MAPIOBJECT
      set rItem = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
      rItem.SaveAs "c:\temp\test.eml", 1024

    For more information, please refer to the following links:

    How to save a mail into an .eml-file with Outlook?

    Save Mail in MIME format (*.eml) in Outlook Add-In

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.






    • Edited by Lina-MSFT Wednesday, October 10, 2018 5:20 AM
    Wednesday, October 10, 2018 5:11 AM
  • Hi Lina,

    Thanks for the reply

    I tried in two ways

    1) First using makeEwsRequestAsync I got all the details of the item, in the below sample, the last asyncResult has the xml response. Is it possible to save it to harddisk as .eml from here? 
    If yes, could you please provide the code sample?

    Office.context.mailbox.item.saveAsync(function (result) {      
        itemId = result.value;
        var soapToGetItemData = getItemDataRequest(result.value);       
        Office.context.mailbox.makeEwsRequestAsync(soapToGetItemData, function (asyncResult) {           
            if (asyncResult.error != null) {
                updateAndComplete("EWS Status: " + asyncResult.error.message);
                return;
            }
            var parser = new DOMParser();
            var doc = parser.parseFromString(asyncResult.value, "text/xml");           
            var values = doc.childNodes[0].getElementsByTagName("t:ItemId");          
            var ItemId = values[0].attributes['Id'].value;            
            var changeKey = values[0].attributes['ChangeKey'].value;  
            var soapToSendItem = getItemRequest(ItemId, changeKey);           
            Office.context.mailbox.makeEwsRequestAsync(soapToSendItem, function (asyncResult) {
                if (asyncResult.error != null) {
                    statusUpdate("EWS Status: " + asyncResult.error.message);
                    return;
                }
                console.log('fulldata');
                console.log(asyncResult);


    2) I made an ajax request from my add-in js to the C# code like specified in this link 

    https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-export-items-by-using-ews-in-exchange#use-the-mime-stream-to-export-into-common-file-formats


    My ExchangeService Object has the ItemId, accesstoken and ewsUrl.

    But it is always resulting in error.

    Using itemId is it possible to get all data of the email and save it?



    Wednesday, October 10, 2018 5:34 AM
  • Hi Jackson,

    I'm afraid there is no better solution to achieve it. Please try the two solutions in my previous reply.

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, October 10, 2018 7:31 AM
  • Hi Jackson,

    Thanks for your asking. Please remember to mark the replies(Include your solution) as answers if they helped and please help us close the thread.

     

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

     

    I wish you a happy life!

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Friday, October 12, 2018 6:53 AM