Showing Exchange Inbox in MOSS 2007
Recently, I have seen a lot of discussions on forums about showing user's mailbox on a portal homepage. This is very similar to the case in My Site, but in this case the portal is not My Site and the requirement is to let each user view his/her mailbox using the My Inbox Web Part.
Interestingly, I have seen developers writing custom Web Part for this requirement. In-fact, this is available totally out of the box.
If you are using Exchange 2007, you can just fill in the Exchange Server field in your Outlook Web Parts for MOSS 2007 and the Web Part will pickup the current user's mailbox automatically.
If you have a Exchange 2003 and SharePoint in your organization, this is one of the strong reason alone for going into Exchange 2007 upgrade, along with other benefits which Exchange 2007 provides.
However, If you are using Exchange 2003 and want to achieve this functionality, its easy to write the custom Web Part which automatically assigns the current user and exchange server to Web Part programmatically. But there are limitations of this approach which I will outline at the end of this post. This is simple code for the Web Part which can be used to assign the username and server name.
using System;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Portal.WebControls;
namespace SharePoint.Webparts
{
public class MyInboxEx : System.Web.UI.WebControls.WebParts.WebPart
{
protected override void CreateChildControls()
{
//Create the instance of My Inbox Web Part
OWAInboxPart inbox = new OWAInboxPart();
//Get and Assign the server name from web.config
inbox.OWAServerAddressRoot = ConfigurationSettings.AppSettings["SERVER_NAME"];
string userName = Page.Request.ServerVariables["LOGON_USER"];
string mailboxName = userName;
int pos = userName.IndexOf("\\");
if (pos > -1)
{
mailboxName = userName.Substring(pos + 1);
}
//Assign the mailbox name
inbox.MailboxName = mailboxName;
Controls.Add(inbox);
}
}
}
In the above code, we can retrieve the server name of exchange server from any configuration store, I am using web.config <AppSettings> section here. Before using this code in any environment, its important to realize its limitations:
- The Web Part makes the assumption that the name of the mailbox is same as the username. Although, this is true for most of Exchange deployments, this is not true for all. I have seen deployments, where FirstName.LastName is used as name of the mailbox while username is entirely different.
- In large Exchange deployments, there are multiple servers being used, and user's mailbox is located to geographically closest server. The Web Part does not take into account of this as we are using single hard coded server name for all the users.
Due to the reasons cited above, the usage of this approach is very limited to small deployments. I have seen this approach being used in one of the deployment at a University :)
Cheers,
Madhur
Comments
Anonymous
July 01, 2008
PingBack from http://stevepietrek.com/2008/07/01/links-712008/Anonymous
January 17, 2009
this code is working but i want to customize the look and feel of the inbox webpart. the problem is - the OWA webparts mycalendar, myinbox, myfolder, all are displaying the whole page from the exchange server.i wants Mycalendar to show only calendar andsimilerly inbox to sho only inbox. cn u help me pls.Anonymous
March 18, 2009
This webpart is just what I have been looking for. However, sharepoint is all quite new to me and would appreicate to be inform as to how his code is implemented into sharepoint? Many thanks!Anonymous
May 15, 2009
http://blogs.msdn.com/mahuja/archive/2008/07/01/showing-exchange-inbox-in-moss-2007.aspxAnonymous
April 07, 2010
I need the same functionality as a custom Web Part which automatically assigns the current user and exchange server to Web Part programmatically. Here I'm using MOSS 2007 and Exchange 2007. The above given code is not working for Exchange 2007.Please mention if there are any additional setting or code has to be added. Thanks!Anonymous
May 02, 2010
Hi, I ahve the same requirement , ie. to display the mails of individual user but I am not using the MS exchange server. We are using java mail server. Can you please let me know how we can achieve the same. Regards, Ankt GoelAnonymous
June 18, 2010
Simi, If you have not resolved your issue yet, send me your email and I will send you a web part that I got from the great Todd Bleeker, which help me too!! Thanks. Nee (nee2ok@yahoo.com)