none
How to change the subject of new mails in Outlook RRS feed

  • Question

  • So, I'm using NewMailEx event for getting the new mails, and I want to change their subject as they load in my Outlook. I have tried something like mailItem.Subject = "MY MESSAGE" + mailItem.Subject and the subject changes but I can see that only clicking the email. In my mailbox, when the mail arrives, the subject is still in the original version only to be changed after I enter the mail to read it.
    Let me show what I'm saying :
    First, I send a message. This is how it appears in Outlook when arrives


    Now, I open the message and see the mail subject changed 

    If I go back to mailbox the mail subject changes

    (the image is in next comment)








     
    Thursday, May 15, 2014 8:42 AM

Answers

  • Outlook doesn't reflect the changes in the UI immediately. As a workaround, you can try to change the current folder programmatically for applying the recent changes. The CurrentFolder property of the Explorer class allows to switch folders on the fly.
    • Marked as answer by Marvin_Guo Wednesday, May 21, 2014 1:47 AM
    Thursday, May 15, 2014 11:45 AM
  • The Outlook object model doesn't provide any event for this. However, you can try to handle Extended MAPI notification events. However, Microsoft doesn't recommend to call Extended MAPI functions from the managed code. You try to use any third-party component in .Net add-ins, for example, Redemption.
    • Marked as answer by Marvin_Guo Wednesday, May 21, 2014 1:47 AM
    Friday, May 16, 2014 1:27 PM

All replies

  • Thursday, May 15, 2014 8:43 AM
  • Outlook doesn't reflect the changes in the UI immediately. As a workaround, you can try to change the current folder programmatically for applying the recent changes. The CurrentFolder property of the Explorer class allows to switch folders on the fly.
    • Marked as answer by Marvin_Guo Wednesday, May 21, 2014 1:47 AM
    Thursday, May 15, 2014 11:45 AM
  • Ok, I understand. but what I found weird is that the subject when it comes in mailbox is still in his original version and after I click on the message it changes. Why I say that? I made a rule for moving every message that contains in the subject the string"MY MESSAGE" to a specific folder but without any success. Maybe its something from my code?

    The event function looks like this 

     private void Application_NewMailEx(string EntryIDCollection)
            {
    
                string[] entryIdArray = EntryIDCollection.Split(',');
                foreach (string entryId in entryIdArray)
                {
    
    
                    try
                    {
    
    
                        Outlook.MailItem item = (Outlook.MailItem)Application.Session.GetItemFromID(entryId,null);
    
    		item.subject = "MY MESSAGE" + item.subject
    
    		.........
    
                    Marshal.ReleaseComObject(item);
    
                   }
    
          }
    
    }


     
    Thursday, May 15, 2014 12:25 PM
  • Instead of changing the subject, you can move the incoming emails to a specific folder without involving rules.
    Thursday, May 15, 2014 12:29 PM
  • still, my code looks ok to you?

    Thursday, May 15, 2014 12:59 PM
  • I don't see anything strange except that you don't release the an instance of the Namespace class which the Session property returned. For example:

    Outlook.MailItem item = (Outlook.MailItem)Application.Session.GetItemFromID ...

    Thursday, May 15, 2014 3:45 PM
  • What I want to know if there is a way to modify the subject of the email before being released in my inbox. If i debug my code when the breakpoint reaches 
     Outlook.MailItem item = (Outlook.MailItem)Application.Session.GetItemFromID(entryId,null);
    then, the mails appears in my inbox.
    Friday, May 16, 2014 9:27 AM
  • The Outlook object model doesn't provide any event for this. However, you can try to handle Extended MAPI notification events. However, Microsoft doesn't recommend to call Extended MAPI functions from the managed code. You try to use any third-party component in .Net add-ins, for example, Redemption.
    • Marked as answer by Marvin_Guo Wednesday, May 21, 2014 1:47 AM
    Friday, May 16, 2014 1:27 PM