none
how to get mail item from MessageId with EWS or MAPI ? RRS feed

  • Question

  • i'm working transport agent service with SmtpReceiveAgent class

    MyReceivedAgent class derived SmtpReceiveAgent and implement to EndOfDataEventHandler.

    priate void OnEndOfDataHandler(ReceiveEventSource source, EndOfDataEventArgs e)
    {
        //insert to DB MessageId Filed [    e.MailItem.Message.MessageId  ]
    }

    i have a question.

    how to get mail item  from MessageId with EWS or MAPI (Exchagne2007 and Exchagne2010 )?

    is it possible ?


    Heetaek,KIM
    Sunday, November 7, 2010 3:04 AM

All replies

  • You need to know the Mailbox the message came from or went to then you can do a search like this on the folder in EWS using the Managed API

          ItemView ivew = new ItemView(1);
          service.TraceEnabled = true;
          ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
          ExtendedPropertyDefinition exProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, 34070, MapiPropertyType.SystemTime);
          SearchFilter sf = new SearchFilter.IsEqualTo(PidTagInternetMessageId, MessageID);
          FindItemsResults<Item> iCol = service.FindItems(WellKnownFolderName.Inbox, sf, ivew);
    
          foreach (Item item in iCol.Items)
          {
            
            Console.WriteLine(item.Subject);
          }
    

     Cheers
    Glen

    Monday, November 8, 2010 2:22 AM
  • It seems not working Glen. Could you please give me the the snippet to read the mail item coming to the inbox of domain\username1 (abc@domain.com)

    Also, what should the messageId be? 

    <7AFC6E50A730F14DB88EE2533A1A9AD61A80B5@domain.com>

    or 7AFC6E50A730F14DB88EE2533A1A9AD61A80B5@domain.com

    or just 7AFC6E50A730F14DB88EE2533A1A9AD61A80B5

     

    THanks

    Wednesday, November 10, 2010 6:29 AM
  • A transport Agents gets a Message in the transport PipeLine (Before) the message has arrived in the Inbox you have the message already in this case in the transport agent there's not need to bind to the Message with EWS. The only area this would be usefull is if you want to find the copy of the sent message in the orginal mailbox you still need to be carefull because this is a copy and Outlook in cache mode i believe changes the ID. What are you trying to do with the Message ?

    Cheers
    Glen

    Thursday, November 11, 2010 2:25 AM
  • um.. thanks Glen

    after insert to database, i want to delete already saved email without OWA or Outlook client.

    are you have a good idea ?

    Thanks.


    Heetaek,KIM
    Monday, November 15, 2010 11:16 AM
  • Sure you could use EWS but in what context ? eg if you have saved the mail using another API use that to delete it.

    Cheers
    Glen

    Tuesday, November 16, 2010 5:23 AM
  • our system must to save all inbound and outbound mail to the database.
    so selected to transport agent service.
    but i'm not found itemId for EWS or MAPI.


    Heetaek,KIM
    Tuesday, November 16, 2010 8:02 AM
  • You need to understand the difference between the Transport Pipeline which is the context a transport Agent operates in and the Message Store which is the context EWS or Mapi operates in. In a transport Agent you intercept the message before its arrived in a mailbox or after its been sent is this case only a copy of the message is stored in the mailbox. The EWS ItemId or the Mapi EntryId are only valid for an Item in a mailbox not for Items your access in the transport Pipeline with a transport Agent. Another way to say this is these properties are non transmittable and a transport agent only allows you to access a message during transmission. An Id that does get transmitted is the Internet messageid but this isn't guaranteed unique and you can't use it to open a message directly. All you can do is a search on a mailbox to find messages that contain this messageid.

    Cheers
    Glen

    Wednesday, November 17, 2010 1:39 AM
  • Hi... I need to get the email using a message ID from Exchange 2010 using EWS.

    Glen... The code above you mentioned does not work since I am not using a managed API. Can you please help me get the email from exchange using its EWS?

    Thanks,

    Jahedur Rahman

    Tuesday, February 1, 2011 6:07 AM