none
EWS Get Unique Emails Every Time i synchronize with inbox Exchange Server RRS feed

  • Question

  • Hi Team,

    I want to store top 10 emails in my data base for reference after regular interval of time.

    I have a question that how can i check if new getting email already exist in my database, can I use "id"  property of Email message for the conversation, IS this ID is unique for every email message? Or any other parameter that which distinguish one email from other?


    Thanks

    Gurbax

    Monday, December 1, 2014 10:44 AM

All replies

  • Hi ,

    By default in exchange there will be an unique message id for each and every messages.Same time we can able to find out which server has generated that message id for the particular message.

    Message-ID: <26640212541001.7371.nithya@mail.abc.com>

    On the above header we can say that mail.abc.com is the server which has generated the message ID for an message.

    Note : we can able to find out the message ID of an particular message through the headers of any message or else via message tracking .Most importantly , exchange will not allow any duplicate messages (i.e emails with same message ID) and by default exchange will drop those kind of duplicate emails.


    Thanks & Regards S.Nithyanandham

    Monday, December 1, 2014 2:11 PM
  • The EWSid while its is unique will change when an Item is moved between folders, the ConversationId should be okay to use but it is computed see http://msdn.microsoft.com/en-us/library/ee204279%28v=exchg.80%29.aspx (the fact it has a GUID should give you relative safety). You could also use PidTagSearchKey see http://msdn.microsoft.com/en-us/library/office/cc815908(v=office.15).aspx which you can access as an extended property, this property can be a good choice because it can be searched on. I would also suggest having a read of http://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx . The one thing to note is that apart from the EWSid most of these other identifiers can be duplicated by a message copy eg if you copied a message to another folder in your mailbox it would have the same SearchKey,ConversationId,InternetmessageId etc as the source message.

    Cheers
    Glen  

    Tuesday, December 2, 2014 2:58 AM
  • Hi Glen,

    Thanks for your Reply..

    1) I  am using below code 

     FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(100));
                ServiceResponseCollection<GetItemResponse> items =
                            service.BindToItems(findResults.Select(item => item.Id), itempropertyset);
    
    
                MailItem[] mailItemsDetail = items.Select(item =>
                {
                    return new MailItem()
                    {
                        From = ((Microsoft.Exchange.WebServices.Data.EmailAddress)item.Item[EmailMessageSchema.From]).Address,
                        Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),
                        Subject = item.Item.Subject,
                        Body = item.Item.Body.ToString(),
                        ConversationID = item.Item.ConversationId,
                        //ConversationInstance =item.Item.ConversationId,
                        DateTimeSent = item.Item.DateTimeSent,
                        EmailMessageID = item.Item.Id.UniqueId,
                        //  PlainEmailText = item.Item.Body.BodyType
                    };
    
                }).ToArray();

    is item.Item.Id.UniqueId gives me the unique id for every email message ?

    2) Also i have a second thread that to retrieve the email message as HTML as well Text both format do i need to pass 

      itempropertyset.RequestedBodyType = BodyType.HTML;

    is there any way the i can pass both prperty set so that i can get both formats in a single EWS call.

    ThanksGurbax

    Wednesday, December 3, 2014 9:57 AM
  •  item.Item.Id.UniqueId  is the ewsId it is unique in the Folder however if the message is moved to another folder in the Mailbox then this Id will change using that Id in a database is covered in http://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx

    2)No depending how the message was sent it may or may not have a Text or HTML Message Body part so when you do request the TextBody or HTML body and the message doesn't have that particular format the Store will do an on the fly conversion see http://msdn.microsoft.com/en-us/library/hh369831%28v=exchg.80%29.aspx  However it will only ever return one body per request you could including the pidNativeBody which maybe a workaround but it depends on the original format.. What might also want try is pulling the MimeContent for the message instead if there was a Text and HTML body in the original message you should get that back in the MimeContent.

    Cheers
    Glen

     
    Thursday, December 4, 2014 6:08 AM