Friday, June 10, 2005

Redemption still needed with Outlook VSTO 2005

One of the things that I had hoped would be improved in the VSTO 2005 Outlook toolkit was that several central MAPI fields should become exposed in the object model. These fields includes being able to change the sender (from) of an e-mail, getting the SMTP address of an Exchange user, getting the URL name of a message, etc.

These things are exactly as before, Microsoft has not added any new functionality to the toolkit, just made it .NET managed code and more reliable. This is 'by design' according to Microsoft, this was the default reply to my wishes during the alpha programme: "VSTO-O does not add any additional functionality to the object model".

During the testing I wanted to set the mail sender without using Redemption. After a suggestion by Sue Mosher I tried by granting a user 'send as' permissions on department mailboxes and changing the sender using the standard SentOnBehalfOfName in the ItemSend event handler, but this never worked. Ken Laws [MSFT] has confirmed that using SentOnBehalfOfName in the ItemSend event is too late, thus you still need Redemption to set this through extended MAPI. This property only works e.g. when set on a Outlook.MailItem created by code.

Changing the sender of an Outlook.MailItem object in ItemSend:

Redemption.SafeMailItem safeMail = new Redemption.SafeMailItemClass();
//Select the item to be modified
safeMail.Item = mailItem;
//fill in the e-mail address in 'From'
int tag = safeMail.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}", "From");
tag = tag 0x1E; //the type is PT_STRING8
safeMail.set_Fields(tag, address);


Getting the SMTP address of an Exchange user from an Outlook.AddressEntry object:

//check if Exchange address
if (mailAddress.StartsWith("/o="))
{
//get SMTP address from MAPI
Redemption.MAPIUtils mapiUtils = new Redemption.MAPIUtils();
int PR_EMAIL = 0x39FE001E;
mailAddress = mapiUtils.HrGetOneProp(entry.MAPIOBJECT, PR_EMAIL).ToString();
mapiUtils.Cleanup();
}

The Outlook toolkit should be reviewed before RTM to add more of the most needed MAPI fields to the list of properties exposed in the object model. Please Microsoft VSTO-O team!

2 comments:

Anonymous said...

This really is by design. If VSTO started updating the Outlook object model, we could run into a situation where there were two competing object models, which would only harm developers.

For the next generation of Outlook, the team is working on improving the object model and adding new functionality.

Kjell-Sverre Jerijærvi said...

Try to actually assign the result from the call to .HrGetOneProp() to a string.