I use the following code to assign some data to an appropriate ContactItem (Sender) of given MailItem. If Sender.GetContact() returns null, I'm trying to create a new ContactItem.
Outlook.MailItem myItem = (Outlook.MailItem)this.OutlookItem;
Outlook.ContactItem currentContact = myItem.Sender.GetContact();
if (currentContact != null)
{
currentContact.Body = "Example";
currentContact.Save();
}
else
{
currentContact = Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
currentContact.Email1DisplayName = myItem.SenderName;
currentContact.Email1Address = myItem.SenderEmailAddress;
currentContact.Email1AddressType = myItem.SenderEmailType;
currentContact.Body = "Example";
currentContact.Save();
}
But this does not seem to work fine for me. The next time I'm getting the contact of that MailItem (see the following code), it returns null. Again. And again.
Outlook.MailItem myItem = (Outlook.MailItem)this.OutlookItem;
Outlook.ContactItem currentContact = myItem.Sender.GetContact();
Is there something wrong? It seems like that new ContactItem is not assigned to Sender.