EWS - out of office message

Hi ,

I'm trying to get the outof office status using EWS api call. For this im able to get the token id but facing problem in the code.

"cannot impicitly convert exchange.weservice.Data.oathcredetials to system.net.icredetials"

Global code:

private String AccessToken;
private String ExchangeEndpointURL;
private ExchangeServiceBinding serviceBinding;

private void SetConfigurationParameters(String OAuthToken_, String ExchangeEndpointURL_){
AccessToken = OAuthToken_;

ExchangeEndpointURL = ExchangeEndpointURL_;
}

private void InitExchangeServiceBinding()
{
//Create Service Binding
serviceBinding = new ExchangeServiceBinding();


//Set OAuth Token
serviceBinding.Credentials = new OAuthCredentials(AccessToken);

//Set Exchange Endpoint URL as specified in configuration
serviceBinding.Url = ExchangeEndpointURL;


Configuration:

SetConfigurationParameters(ExchangeEndpointURL, OAuthToken);


Out of office code:

InitExchangeServiceBinding();

oooMessage ="";

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 = EmailToCheck;
gmType.Recipients[0] = rcip;
EmailAddressType sendAs = new EmailAddressType();
sendAs.EmailAddress = Username;
gmType.SendingAs = sendAs;

GetMailTipsResponseMessageType gmResponse = serviceBinding.GetMailTips(gmType);

ExceptionMessage="";

if (gmResponse.ResponseClass == ResponseClassType.Success)
{
if (gmResponse.ResponseMessages[0].MailTips.OutOfOffice == null)
{
ExceptionMessage = "Could not get an Out of Office message for email address: " + EmailToCheck;
Success = false;
}
else {
oooMessage = gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message;
}


}
else {
ExceptionMessage = "Unexpected error when calling EWS: " + gmResponse.MessageText.ToString();
Success = false;
}

Success = true;




View attachment 1591346265664.png
View attachment 1591346403003.png
 

Attachments

  • 1591346297490.png
    77.8 KB · Views: 0
Top