Get Out of Office settings from Transport Agent

Hello.

I need to get OOF settings for user from Transport agent. I have found this article: 

http://msdn.microsoft.com/en-us/library/office/exchangewebservices.getuseroofsettingsrequest(v=exchg.150).aspx

How I should create ExchangeServiceBinding to get OOF settings for user@mail.com for example?

Thanks in advance.


October 27th, 2014 3:15pm

If your running Exchange 2010 or later then you would be better of using MailTips rather than the Oofsetting operations as MailTips doesn't require you to have access to the particular Mailbox. eg to Get the OOF mailtip you can use

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   
    }   
                     
}  

Be careful about making these type of requests in a Transport Agent as they can be very detrimental to the performance and the message throughput of a Transport server if you doing this type of lookup on every message. You need to think about how this will might work in high availability situations also.

Cheers
Glen

  • Marked as answer by Metelitca Wednesday, October 29, 2014 11:09 AM
Free Windows Admin Tool Kit Click here and download it now
October 28th, 2014 5:04am

You can use

Get-MailboxAutoReplyConfiguration user.com

October 28th, 2014 6:06am

Hi Metelitca,

I'm with Supriya, you shoud rather use the cmdlet as the first approach using EWS required Mailbox Access (please see the credentials in that script). For running the cmdlet via (remote) Powershell, you can use some code like

namespace Microsoft.Samples.PowerShell.Runspaces {  

using System;  
using System.Management.Automation;  
using PowerShell = System.Management.Automation.PowerShell;    

internal class getExchangeInfo  {    

private String username = "user@domain.com";     
  private static void Main(string[] args)    {      
... your code     
  }     

  private static getOutofOffice () 
using (PowerShell powershell = PowerShell.Create().AddCommand("get-mailboxautoreplyconfiguration " + username))      {     
      foreach (PSObject result in powershell.Invoke())        {  
... do something with the result from ps ..
           }
      }
   }  
  }
}

If you Need more Information about the Powershell wrapper in your C# code, please see http://msdn.microsoft.com/en-us/library/ee706576(v=vs.85).aspx (These are the ones with Powershell) ; if you Need additional Information about get-mailboxautoreplyconfiguration, see http://technet.microsoft.com/de-de/library/dd638081(v=exchg.150).aspx .

Your account by default required Recipient Management permissions if you Need to modify the OOF

Please let us know, if it worked.

Regards,
Martin

Free Windows Admin Tool Kit Click here and download it now
October 28th, 2014 7:28am

How do I again access to the JAR that contains these classes?

ExchangeServiceBinding

July 30th, 2015 10:17pm

ExchangeServiceBinding is a proxy class generated from the EWS WSDL file if your using Java I'd suggest you start with http://www.thesoftwaregorilla.com/2010/05/exchange-web-services-example-part-1-introduction-and-set-up/  or take a look at the https://github.com/OfficeDev/ews-java-api

Cheers
Glen

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 11:53pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics