Search code examples
emailoutlookvstooutlook-addinoffice-addins

VSTO Outlook: Get last email address just entered in the "To", "Bc" or "Cc" fields in new, reply or forward windows


I am trying to get the last recipient (email address) just introduced into the "To", "Bc" or "Cc" fields when field loses its focus. How can I achieve this?

For example:

  • if user just types in an email address within "To" field I want to get that.
  • if user just types in an email address within "Bc" field I want to get that.
  • if user just types in an email address within "Cc" field I want to get that.

Solution

  • Use MailItem.PropertyChange event. Whenever any recipient is changed (added/deleted), the event handler fires for all 3 (To/CC/BCC) properties, so your won't know which one changed. You'd need to cache the old value first, and when the event fires, compare it with new value.

    PropertyChange ("To")
    PropertyChange ("CC")
    PropertyChange ("BCC")