Skip to content

Instantly share code, notes, and snippets.

@VibhuKuchhal
Last active April 19, 2016 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VibhuKuchhal/220a3914a4ebe96c438e to your computer and use it in GitHub Desktop.
Save VibhuKuchhal/220a3914a4ebe96c438e to your computer and use it in GitHub Desktop.
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