setting MAPI properties through PropertyAccessor

N

Nikolas

Hi,

I've been trying to set some properties to a new MailItem through
PropertyAccessor using C#, VS 2005 and VSTO SE Beta. My aim is to create a
new MailItem that has some of the same properties of another MailItem. Using
MAPI you could do it using the IMAPIProp::CopyTo() function and specifying
which properties you wanted to copy from one MailItem to another. Is there a
way of doing this with the new Outlook object model?

What I tried so far was to create a new MailItem and then tried through the
PropertyAccessor to set the properties one by one. It fails to all of them by
throwing an exception with message: "The operation failed."

Note that the new MailItem does not have all the properties of the old
MailItem. Is that an issue? I understand that some of the properties have a
read only access but still there must be a way of changing them like there is
in MAPI.

Here is what I do:

string propertyName = "http://schemas.microsoft.com/mapi/proptag/0x0E070003"

MailItem newMailItem = this.Application.CreateItem(OlItemType.olMailItem) as
MailItem;

int value = oldMailItem.PropertyAccessor.GetProperty(propertyName);
newMailItem.PropertyAccessor.SetProperty(propertyName, value);

The last line throughs the exception.

Any help would much appreciated.
 
K

Ken Slovak - [MVP - Outlook]

You'd be better off posting programming questions to a programming group.

PR_MESSAGE_FLAGS is a computed property. I'm not sure that you can set it
using Extended MAPI, but you certainly can't set it using the OOM or CDO or
even using OutlookSpy. Trying to change the flags using OutlookSpy I get a
MAPI_E_COMPUTED error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top