Tag Archives: ExchangeUser

EWS : How to access user’s free/busy info programmatically using Exchange Web Services (EWS)?


In this post, we will see how to access user free/busy information programmatically using Exchange Web Services (EWS) – Proxy. Exchange provides such a service by storing what is referred to as free/busy data. This information will indicate what requested time range is free, busy, and tentative for a particular user. It will also provide any out of office (oof) status as well. Free/Busy data can be obtained using the Availability service provided by the Exchange Server. This is simply a web service which obtains the free/busy data directly from a user’s calendar.

Specifically, the GetUserAvailability operation will provide the free/busy state at specific level of detail.Using GetUserAvailability operation, which provides current user availability information at a specified level of detail – about the availability of a set of users, rooms, and resources within a specified time period. Client applications such as Microsoft Office Outlook, Microsoft Outlook Web Access, Microsoft Outlook Mobile Access, and other applications use SMTP addresses to identify the requested user information.

Let start now by creating the binding, set the credentials/URL and pass the binding (esb) to the following functionality ( which I haven’t added here).

Identify the time to compare free/busy information:

Duration duration = new Duration();

duration.StartTime = DateTime.Now;

duration.EndTime = DateTime.Now.AddHours(4);


Identify the options for comparing free/busy information:

FreeBusyViewOptionsType fbViews = new FreeBusyViewOptionsType();

fbViews.TimeWindow = duration;

fbViews.RequestedView = FreeBusyViewType.MergedOnly;

fbViews.RequestedViewSpecified = true;

fbViews.MergedFreeBusyIntervalInMinutes = 35;

fbViews.MergedFreeBusyIntervalInMinutesSpecified = true;


Identify the user mailbox to review for free/busy data:
MailboxData[] mbx=
newMailboxData[1];

mbx[0] = new MailboxData();

EmailAddress emailAddress = new EmailAddress();

emailAddress.Address = "user1@domain.com";

emailAddress.Name = String.Empty;

mbx[0].Email = emailAddress;

mbx[0].ExcludeConflicts = false;

Make the request and set the time zone of the request:
getusrRequest.TimeZone = newSerializableTimeZone();

getusrRequest.TimeZone.Bias = 480;

getusrRequest.TimeZone.StandardTime = newSerializableTimeZoneTime();

getusrRequest.TimeZone.StandardTime.Bias = 0;

getusrRequest.TimeZone.StandardTime.DayOfWeek = DayOfWeekType.Sunday.ToString();

getusrRequest.TimeZone.StandardTime.DayOrder = 1;

getusrRequest.TimeZone.StandardTime.Month = 11;

getusrRequest.TimeZone.StandardTime.Time = "02:00:00";

getusrRequest.TimeZone.DaylightTime = new SerializableTimeZoneTime();

getusrRequest.TimeZone.DaylightTime.Bias = -60;

getusrRequest.TimeZone.DaylightTime.DayOfWeek = DayOfWeekType.Sunday.ToString();

getusrRequest.TimeZone.DaylightTime.DayOrder = 2;

getusrRequest.TimeZone.DaylightTime.Month = 3;

getusrRequest.TimeZone.DaylightTime.Time = "02:00:00";


In addition to that, add the mailbox and the view options to the request
getusrRequest.MailboxDataArray = mbx;

getusrRequest.FreeBusyViewOptions = fbViews;


Send the above request and get the response:
GetUserAvailabilityResponseType getusrResponse = esb.GetUserAvailability(getusrRequest);


Access the free/busy info:

if(getusrResponse.FreeBusyResponseArray.Length < 1)

{

Console.WriteLine("No free/busy response data available.");

}

else

{

foreach(FreeBusyResponseType fbrt in getusrResponse.FreeBusyResponseArray)

{

if(fbrt.ResponseMessage.ResponseClass == ResponseClassType.Error)

{

Console.WriteLine("Error:" + fbrt.ResponseMessage.MessageText);

}

else

{

FreeBusyView fbv = fbrt.FreeBusyView;

Console.WriteLine("Merged free/busy data: " + fbv.MergedFreeBusy);

}

}

}


If you run the above piece of code, then you will get the result:

clip_image001[17]

For more information, you can refer the following article: http://msdn.microsoft.com/en-us/library/aa564001(v=exchg.140).aspx

Happy programming!!

Outlook 2007 : How to obtain Proxy addresses using Outlook Object Model (for an ExchangeUser Object)?


Earlier i had a requirement, how to obtain Proxy addresses for a specific user programmatically’; also they preferred to do this by using Outlook Object Model API.

Please Note:

  • The ExchangeUser object does not directly expose the proxy addresses for the user.
  • However, you can use the PropertyAccessor object to obtain the MAPI property PR_EMS_AB_PROXY_ADDRESSES.
  • This property is a multi-valued string property that contains all the foreign addresses for a given user.

Here is a simple code snippet, which returns an array of strings containing the proxy addresses for the ExchangeUser object passed as a method argument.

private string[] GetProxyAddresses(Outlook.ExchangeUser exchUser) 
{ 
    const string PR_EMS_AB_PROXY_ADDRESSES = "http://schemas.microsoft.com/mapi/proptag/0x800F101E"; 
    if (exchUser != null) 
    { 
        return exchUser.PropertyAccessor.GetProperty( 
            PR_EMS_AB_PROXY_ADDRESSES) as string[]; 
    } 
    else 
    { 
        throw new ArgumentNullException(); 
    } 
}

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

Hope this helps.

Outlook Object Model : How to programmatically get logged-in user’s CompanyName in Outlook 2003/2007?


Recently one of my customer updated that they have a requirement to implement the following logic:

1) Get Contact info from GAL or Address book for the specified contact
2) Get Contact information regarding his CompanyName etc.

In the scenario, i provided the following suggestions:

If you try Outlook 2003 & its prior versions: Using the Microsoft Outlook object model, you can access information that is stored in various address books. For example, you can retrieve information about entries in the Global Address Book, or an Outlook Address Book. But if you want to access additional entries that are typically available for a recipient (such as Office, Title or Phone) you can use the Collaboration Data Objects (CDO) object model.

You can try like this CDO code snippet… This code fragment compares the Address property of the Recipient object with the Address and Type properties of its child AddressEntry object, accessible through the recipients AddressEntry property, to demonstrate the relationships between these properties.

    If objOneRecip Is Nothing Then
        MsgBox "must select a recipient"
        Exit Function
    End If
    Set objAddrEntry = objOneRecip.AddressEntry
    If objAddrEntry Is Nothing Then
        MsgBox "no valid AddressEntry for this recipient"
        Exit Function
    End If
 
 
    strMsg = "Recipient full address = " & objOneRecip.Address
    strMsg = strMsg & "; AddressEntry type = " & objAddrEntry.Type
    strMsg = strMsg & "; AddressEntry address = " & objAddrEntry.Address
    MsgBox strMsg ' compare display names
    strMsg = "Recipient name = " & objOneRecip.Name
    strMsg = strMsg & "; AddressEntry name = " & objAddrEntry.Name
 
 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

For more information about accessing these properties using CDO and detailed information, please see the following articles in the Microsoft Knowledge Base:

HOWTO: Read Address Book Properties in Visual Basic
http://support.microsoft.com/kb/179083/EN-US/

HOWTO: Work with Distribution Lists Using CDO from VB
http://support.microsoft.com/kb/178787/EN-US/

Note: CDO 1.2x/MAPI are not supported in a .NET Framework environment. Refer: http://support.microsoft.com/kb/813349

If you work with Outlook 2007 and later, then you can try using ExchangeUser Object. This object provides first-class access to properties applicable to Exchange users. You can also access other properties specific to the Exchange user that are not exposed in the object model through the PropertyAccessor object.

I tried the VBA code sample and obtain the CompanyName.

Sub GetUserCompany()
 
    Dim oExUser As Outlook.ExchangeUser
 
    'Obtain the AddressEntry for CurrentUser
    Set oExUser = Application.Session.CurrentUser.AddressEntry.GetExchangeUser
 
    MsgBox oExUser.CompanyName
 
 End Sub

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

You need to note that, “some of the explicit built-in properties are read-write properties. Setting these properties requires the code to be running under an appropriate Exchange administrator account; without sufficient permissions, calling the ExchangeUser.Update method will result in a “permission denied” error.”

Hope this helps!! Happy programming & happy holidays!!