none
MailItem.EntryID Changed RRS feed

  • Question

  • I found EntryID will be change when MailItem sent from the draft box to the Sentbox

    How can I get the EntryID still ?

    	Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
    

     
            void Application_ItemSend(object Item, ref bool Cancel)
            {
    		// Cancel = true; //取消发送
    
                    Outlook.MailItem mailItem = Item as Outlook.MailItem;
                    if (mailItem != null)
                    {
     
                        //如果是新建邮件未存之前mailItem.EntryID为空
                        mailItem.Save();
    
                        string mailid = mailItem.EntryID;
                        if (mailid != "")
                        {
                            clsMailIDPool mp = new clsMailIDPool(mailid);
                            mp.MailID = mailid;
                            mp.DealDate = DateTime.Now;
                            mp.MailSubject = mailItem.Subject;
                            mp.MType = 1;
                            mp.MarkType = clsMailIDPool.GetEnumIdByName(frmSendMark.ShowSelectBox());
    
                            //MessageBox.Show(mp.MarkType.ToString());
    
                            clsMailIDPool.Insert(mp);
                        }
                        Marshal.ReleaseComObject(mailItem);
                        mailItem = null;
                    }
            }

    		    Outlook.NameSpace outlookNameSpace = Application.GetNamespace("MAPI");
                        Outlook.MAPIFolder sentbox = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
    
                        Outlook.Items items = sentbox.Items.Restrict("[SentOn]>'" + DateTime.Now.Date.ToString("yyyy-MM-dd") + "'");
                        foreach (Outlook.MailItem mailItem in items)
                        {
                            string mailid = mailItem.EntryID;
                            clsMailIDPool.CheckIDExists(mailid);  //EntryID was changed,Application_ItemSend saved MailID not exist..
                        }
                        Marshal.ReleaseComObject(items);
                        items = null;
                        Marshal.ReleaseComObject(sentbox);
                        sentbox = null;
                        Marshal.ReleaseComObject(outlookNameSpace);
                        outlookNameSpace = null;

    Wednesday, October 28, 2015 3:50 AM

Answers

  • This is to be expected - entry id is changed when an item is moved between folders. PST provider is the only one that does not change the entry ids when items are moved, but it is an exception rather than a rule, and you should always expect the entry id to change.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 28, 2015 9:12 PM

All replies

  • Hello Leo,

    The Entry ID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved.

    You may consider moving your items to a custom folder where you can find and process such items. The SaveSentMessageFolder property allows to set a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent. For example:

    Sub SetSentFolder() 
     Dim myItem As Outlook.MailITem  
     Dim myResponse As Outlook.MailITem 
     Dim mpfInbox As Outlook.Folder 
     Dim mpf As Outlook.Folder 
     
     Set mpfInbox = Application.Session.GetDefaultFolder(olFolderInbox) 
     Set mpf = mpfInbox.Folders.Add("SaveMyPersonalItems") 
     Set myItem = Application.ActiveInspector.CurrentItem 
     Set myResponse = myItem.Reply 
     myResponse.Display 
     myResponse.To = "Eugene Astafiev" 
     Set myResponse.SaveSentMessageFolder = mpf 
     myResponse.Send 
    End Sub

    Wednesday, October 28, 2015 8:20 AM
  • This is to be expected - entry id is changed when an item is moved between folders. PST provider is the only one that does not change the entry ids when items are moved, but it is an exception rather than a rule, and you should always expect the entry id to change.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 28, 2015 9:12 PM
  • The entry id also changes when an items is moved between two folders in the same store. PST is the only exception.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, October 29, 2015 2:14 AM
  • tks Eugene Astafiev
    Friday, October 30, 2015 1:01 AM
  • tks, Dmitry Streblechenko
    Friday, October 30, 2015 1:02 AM
  • Hi Leo,

    If your issue has been resolved, I suggest you mark the helpful reply as answer to close this thread, and then others who meet the same issue could find the solution quickly.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 30, 2015 2:47 AM
  • tks,done
    Friday, October 30, 2015 3:14 AM