none
How to download mail in different format using Microsoft Exchange Web Services Managed API 2.0? RRS feed

  • Question

  • Environment:  -

    Exchange Server: - Exchange Server 2010 SP3

    EWS API: - 2.0

    IDE: - Visual Studio 2008

    Language: - C#

    .

    Requirement: -

    .

    We are designing a C# based exe utility, which will download mail in following format: -

    1- HTML

    In case of HTML, following are the possibilities: -  

    .

          i- Separate attachment with mail body

        Task: - If Attachments are separate, then we need to dump attachments in some folder and maintain body as body.html

    .

          ii- Embed attachment with mail body

        Task: - If Attachments are embedding, and then we need to dump attachments and body as body.mht

    .

         iii- Embed attachment within mail body, and also having separate attachment in mail

       Task: - Separate attachments will be saved in some folder and embed attachment, message body will be saved as body.mht

    .

    2- Plain Text

        i- Separate attachment with mail body

      Task: -Separate attachment will be saved in some folder, and body will be saved as body.txt

    .

    .

    Following challenges, we are facing in development: -

    Q: - How will we know Attachments are coming separate, Embed or both?

    .

    Q: - If attachments are Embed in body, then how will we save body as mht?

    .

    Kindly assist, I will be really thankful.



    • Edited by S.P Singh Saturday, August 1, 2015 4:15 PM Formatted properly
    Saturday, August 1, 2015 10:30 AM

Answers

  • I have read from above link and written some code snippet, which works fine for knowing Inline and separate attachment. It can also useful for others.


    var inbox = new FolderId(WellKnownFolderName.Inbox);

    var iv = new ItemView(10);

    var items = service.FindItems(inbox,iv);

    int itemsCountInInbox = items.TotalCount;

    MessageBox.show("Total emails for processing: " + itemsCountInInbox);

    foreach (Attachment attachmentProcess in msg.Attachments)

    {                       

         if (attachmentProcess.IsInline == true)

         {

           MessageBox.show (" Inline " + attachmentProcess.Name);

         }

         else

         {

           MessageBox.show (" Separate " + attachmentProcess.Name);

         }

    }


    Regards, S.P Singh

    • Marked as answer by S.P Singh Thursday, August 6, 2015 10:02 AM
    Thursday, August 6, 2015 10:02 AM

All replies

  • 1. Check the property on the Attachment https://msdn.microsoft.com/en-us/library/office/dd633665(v=exchg.80).aspx itself. Depends what you mean by embedded do you mean Exchange Store types ? these are called ItemAttachments in EWS.

    2. see https://msdn.microsoft.com/en-us/library/office/dn672317(v=exchg.150).aspx which has a sample of saving a message as an MHT file.

    Cheers
    Glen

    Monday, August 3, 2015 2:54 AM
  • Thanks Sir,

          I have gone through first link and found two terms “File Attachment” and “Item Attachment”. It seems to me that 

    "File attachment is any file and the item attachment is an exchange element like an appointment"

    What else comes in category of Item Attachments?


    Regards, S.P Singh

    Monday, August 3, 2015 5:00 AM
  • I have read from above link and written some code snippet, which works fine for knowing Inline and separate attachment. It can also useful for others.


    var inbox = new FolderId(WellKnownFolderName.Inbox);

    var iv = new ItemView(10);

    var items = service.FindItems(inbox,iv);

    int itemsCountInInbox = items.TotalCount;

    MessageBox.show("Total emails for processing: " + itemsCountInInbox);

    foreach (Attachment attachmentProcess in msg.Attachments)

    {                       

         if (attachmentProcess.IsInline == true)

         {

           MessageBox.show (" Inline " + attachmentProcess.Name);

         }

         else

         {

           MessageBox.show (" Separate " + attachmentProcess.Name);

         }

    }


    Regards, S.P Singh

    • Marked as answer by S.P Singh Thursday, August 6, 2015 10:02 AM
    Thursday, August 6, 2015 10:02 AM