Last active
April 19, 2016 05:05
-
-
Save VibhuKuchhal/220a3914a4ebe96c438e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Exchange.WebServices.Data; | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.IO; | |
using System.Linq; | |
public class ExchangeRepository | |
{ | |
ExchangeService serviceInstance; | |
public string ExceptionMessage { get; } | |
public ExchangeRepository() | |
{ | |
serviceInstance = new ExchangeService(ExchangeVersion.Exchange2013_SP1); | |
//Provide the account user name in format vibhu.kuchhal@contoso.com | |
serviceInstance.Credentials = new WebCredentials(ConfigurationManager.AppSettings["User"].ToString(), ConfigurationManager.AppSettings["Password"].ToString()); | |
try | |
{ | |
// Use Autodiscover to set the URL endpoint. | |
// and using a AutodiscoverRedirectionUrlValidationCallback in case of https enabled clod account | |
serviceInstance.AutodiscoverUrl(ConfigurationManager.AppSettings["MailBox"].ToString(), SslRedirectionCallback); | |
} | |
catch (Exception ex) | |
{ | |
serviceInstance = null; | |
ExceptionMessage = ex.Message; | |
} | |
} | |
bool SslRedirectionCallback(string serviceUrl) | |
{ | |
// Return true if the URL is an HTTPS URL. | |
return serviceUrl.ToLower().StartsWith("https://"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment