I am working on an add-in add-in where I need to set a custom header. I am using VS2010 for my development.
I am trying to use the following code, but it does not work.
private void AddUserProperty(Outlook.MailItem mail, string folderEmailId)
{
Outlook.PropertyAccessor mailPropertyAccessor = null;
try
{
if (string.IsNullOrEmpty(folderEmailId))
return;
mailPropertyAccessor = mail.PropertyAccessor;
mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId", folderEmailId);
mail.Save();
try
{
MessageBox.Show("Existing :" + mail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId"));
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
catch (System.Exception ex)
{
Logger.Error(ex);
MessageBox.Show(ex.Message);
}
finally
{
if (mailPropertyAccessor != null)
Marshal.ReleaseComObject(mailPropertyAccessor);
}
}
After saving the mail item, I try to get the same item for verification, but it throws an exception saying that the property was not found.
source
share