Monday, December 05, 2005

How to configure your MyInbox webpart automatically ?

It seems to be so difficult to configure your SharePoint Outlook webparts automatically, but it isn't !

Last week, I tried everything, but I failed to configure those Outlook webparts.
It seems to be nobody wants to configure a MyInbox automatically for every user on the MySite. I didn't found any website or blog with information, I just found some questions on forums without an answer.

So, Can I conclude that every user must know the servername and his mailboxname ?
No, it's irrealistic in my opinion !
This morning, I had 'one of my famous intelligent moments' *d'oh*

So, here's the one and only, the solution !

Follow the autoConfig lab below to succeed the configuration for every user at runtime

1. Create a new Webpart Library project
2. Override the CreateChildControls

// import section
using Microsoft.SharePoint.Portal.WebControls;

// attributes
private OWAInboxPart wpInbox;

protected override void CreateChildControls()
// inbox webpart
wpInbox = new OWAInboxPart();


3. Create a new method to configure your Inbox webpart. This method will determine the mailboxname and the servername at runtime for a particular user.

private OWAInboxPart configureInbox(OWAInboxPart wpInbox)
//Connect to the portal and get the portal context.
TopologyManager topology = new TopologyManager();
PortalSite portal = topology.PortalSites[new Uri(
PortalContext context = PortalApplication.GetContext(portal);

//initialize user profile config manager object
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile prof = profileManager.GetUserProfile(true);

// use the profile object to retrieve the properties you need in your company to
// retrieve the mailboxname
// example: string workmail = prof[PropertyConstants.WorkEmail].ToString();
wpInbox.MailboxName = "kristofdc";

wpInbox.OWAServerAddressRoot = "http://servername/exchange";

return wpInbox;


4. Override the RenderWebPart method

protected override void RenderWebPart(HtmlTextWriter output)
catch(Exception ex)


5. And finally you will add a CAB-setup for your custom webpart.
6. Just compile, deploy and use !

This MyInbox example works also with the MyCalendar & MyTasks.

Success garanteed !

Happy Programming !
The Sharepoint Factory Geek


Gustaf Westerlund said...

Great code, I almost got it to work but I seem to have some security issues when trying to instantiate the TopologyManager. I am using a VPC and the user running the SharePoint AppPool is the domain administrator and is included in the two securitygroups specified in the SDK. The user is also in the db_owner role in the config db.

The error I get is:
System.Security.SecurityException: Request failed. at Microsoft.SharePoint.Portal.Topology.TopologyManager.g() at Microsoft.SharePoint.Portal.Topology.TopologyManager..ctor() at MyInboxAC.MyInboxAC.configureInbox(OWAInboxPart wpInbox) in c:\documents and settings\administrator\my documents\visual studio projects\myinboxac\myinboxac.cs:line 78 at MyInboxAC.MyInboxAC.CreateChildControls() in c:\documents and settings\administrator\my documents\visual studio projects\myinboxac\myinboxac.cs:line 60

Any ideas?
If I hardcode the credentials, there is no problem. It works like a charm!


Gustaf Westerlund said...

I fixed it.

It had to do with the trust level settings. I had WSS_Medium and it didn't work but when I used Full it worked. Hence I believe it has to be placed in the GAC with a strongname to work properly.

Bob C said...

What are the steps to build a cab project that will work for the dwp?

Bob C said...

Figured out the .cab project. Had to add the Content Files to the output. Then stsadm -o addwppk -globalinstall

My remaining question is about the v2 PortalApplication class. Should this work in v3? When I am in vs the compiler warns that these are obsolete. Does that mean they wont work, or are due to be removed from the spec?

Anonymous said...

thanks for your helpful code but i need user to login on his mail box without asking about user name and password

Anonymous said...

I'm trying to create the MyInbox web part following your code, but i couldn't find on my disk the Microsoft.SharePoint.Portal.dll assembly. Could you please tell me what should i have installed to have this assembly?

Kristof De Causemaeker said...


You must install Sharepoint on your development machine to use the Microsoft.Sharepoint.Portal.dll.

Anonymous said...

Hello i want to now if there is a way of I can hardcode the mail box so it would go to just the 1 mail box and if i could hardcode the username + password for that mail box
If you know you would save my life :)

Dan said...

Dear Kristof,

Do you have a listing of the actual code?
I am trying to implement your solution and I get errors, when I compile the program, using Visual Studio 2005.
Any help would be greatly appreciated, with this.