MailTips is one of the really useful new features of Exchange 2010 that can be exceedingly useful to anybody using Exchange Web Services. It provides access to Information such as the OOF status of a user or users within one WebService call and without the need for Full Access or elevated rights you would normally need with a GetUserOofSettings operations or using the Remote powershell cmdlets such as Get-MailboxAutoReplyConfiguration.
The other thing MailTips are useful for apart from the other standard Mail-tips listed http://msdn.microsoft.com/en-us/library/dd877060%28v=exchg.140%29.aspx (things like the Max message size is useful for anybody sending email via EWS etc) is the ability to create Custom MailTips. This gives you the ability to now retrieve a custom property that is stored within Active Directory via EWS. Which provides a workaround to not being able to access the information in the AD Custom Attributes http://technet.microsoft.com/en-us/library/ee423541.aspx currently in EWS.
To use the EWS Mailtips operations you need to use WSDL Proxy objects or Custom SOAP code as currently these operations aren't available for use within the EWS Managed API. If you want to script it I would still combine it with EWS Managed API code because of ease of access to things like Autodiscover this gives you.
I've created a powershell and C# sample of using the GetMailtips operation the C# looks like
With the Powershell example the following information needs to be configured
$MailboxName = "sender@domain.com"
Mailbox which will do the check from
$Mailboxes = @("user1@domain.com","user2@domain.com")
Mailbox you want to check the OOF of (this is just an array or Strings)
$cred = New-Object System.Net.NetworkCredential("user1@domain.com","password@#")
Credentials to use
I've put a download of the script here the code itself looks like
The other thing MailTips are useful for apart from the other standard Mail-tips listed http://msdn.microsoft.com/en-us/library/dd877060%28v=exchg.140%29.aspx (things like the Max message size is useful for anybody sending email via EWS etc) is the ability to create Custom MailTips. This gives you the ability to now retrieve a custom property that is stored within Active Directory via EWS. Which provides a workaround to not being able to access the information in the AD Custom Attributes http://technet.microsoft.com/en-us/library/ee423541.aspx currently in EWS.
To use the EWS Mailtips operations you need to use WSDL Proxy objects or Custom SOAP code as currently these operations aren't available for use within the EWS Managed API. If you want to script it I would still combine it with EWS Managed API code because of ease of access to things like Autodiscover this gives you.
I've created a powershell and C# sample of using the GetMailtips operation the C# looks like
- ExchangeServiceBinding esb = new ExchangeServiceBinding();
- esb.Credentials = new NetworkCredential("user@domain.com", "password", "");
- esb.Url = "https://ch1prd0302.outlook.com/EWS/Exchange.asmx";
- esb.RequestServerVersionValue = new RequestServerVersion();
- esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;
- GetMessageTrackingReportRequestType gmt = new GetMessageTrackingReportRequestType();
- GetMailTipsType gmType = new GetMailTipsType();
- gmType.MailTipsRequested = new MailTipTypes();
- gmType.MailTipsRequested = MailTipTypes.OutOfOfficeMessage;
- gmType.Recipients = new EmailAddressType[1];
- EmailAddressType rcip = new EmailAddressType();
- rcip.EmailAddress = "user@domain.com";
- gmType.Recipients[0] = rcip;
- EmailAddressType sendAs = new EmailAddressType();
- sendAs.EmailAddress = "sender@domain.com";
- gmType.SendingAs = sendAs;
- GetMailTipsResponseMessageType gmResponse = esb.GetMailTips(gmType);
- if (gmResponse.ResponseClass == ResponseClassType.Success) {
- if (gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message != "")
- {
- //User Out
- Console.WriteLine(gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message);
- }
- else {
- //user In
- }
- }
$MailboxName = "sender@domain.com"
Mailbox which will do the check from
$Mailboxes = @("user1@domain.com","user2@domain.com")
Mailbox you want to check the OOF of (this is just an array or Strings)
$cred = New-Object System.Net.NetworkCredential("user1@domain.com","password@#")
Credentials to use
I've put a download of the script here the code itself looks like
- $MailboxName = "sender@domain.com"
- $Mailboxes = @("user1@domain.com","user2@domain.com")
- $cred = New-Object System.Net.NetworkCredential("user1@domain.com","password@#")
- $dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll"
- [void][Reflection.Assembly]::LoadFile($dllpath)
- $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
- $service.TraceEnabled = $false
- $service.Credentials = $cred
- $service.autodiscoverurl($MailboxName,{$true})
- $expRequest = @"
- <?xml version="1.0" encoding="utf-8"?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Header><RequestServerVersion Version="Exchange2010_SP1" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
- </soap:Header>
- <soap:Body>
- <GetMailTips xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
- <SendingAs>
- <EmailAddress xmlns="http://schemas.microsoft.com/exchange/services/2006/types">$MailboxName</EmailAddress>
- </SendingAs>
- <Recipients>
- "@
- foreach($mbMailbox in $Mailboxes){
- $expRequest = $expRequest + "<Mailbox xmlns=`"http://schemas.microsoft.com/exchange/services/2006/types`"><EmailAddress>$mbMailbox</EmailAddress></Mailbox>"
- }
- $expRequest = $expRequest + "</Recipients><MailTipsRequested>OutOfOfficeMessage</MailTipsRequested></GetMailTips></soap:Body></soap:Envelope>"
- $mbMailboxFolderURI = New-Object System.Uri($service.url)
- $wrWebRequest = [System.Net.WebRequest]::Create($mbMailboxFolderURI)
- $wrWebRequest.KeepAlive = $false;
- $wrWebRequest.Headers.Set("Pragma", "no-cache");
- $wrWebRequest.Headers.Set("Translate", "f");
- $wrWebRequest.Headers.Set("Depth", "0");
- $wrWebRequest.ContentType = "text/xml";
- $wrWebRequest.ContentLength = $expRequest.Length;
- $wrWebRequest.Timeout = 60000;
- $wrWebRequest.Method = "POST";
- $wrWebRequest.Credentials = $cred
- $bqByteQuery = [System.Text.Encoding]::ASCII.GetBytes($expRequest);
- $wrWebRequest.ContentLength = $bqByteQuery.Length;
- $rsRequestStream = $wrWebRequest.GetRequestStream();
- $rsRequestStream.Write($bqByteQuery, 0, $bqByteQuery.Length);
- $rsRequestStream.Close();
- $wrWebResponse = $wrWebRequest.GetResponse();
- $rsResponseStream = $wrWebResponse.GetResponseStream()
- $sr = new-object System.IO.StreamReader($rsResponseStream);
- $rdResponseDocument = New-Object System.Xml.XmlDocument
- $rdResponseDocument.LoadXml($sr.ReadToEnd());
- $RecipientNodes = @($rdResponseDocument.getElementsByTagName("t:RecipientAddress"))
- $Datanodes = @($rdResponseDocument.getElementsByTagName("t:OutOfOffice"))
- for($ic=0;$ic -lt $RecipientNodes.length;$ic++){
- if($Datanodes[$ic].ReplyBody.Message -eq ""){
- $RecipientNodes[$ic].EmailAddress + " : In the Office"
- }
- else{
- $RecipientNodes[$ic].EmailAddress + " : Out of Office"
- }
- }