示例#1
0
        private EWSConnection ConnectToEWS(Credentials credentials)
        {
            Logger.Debug($"Initializing FolderMailboxManager for email address {credentials.EmailAddress}");
            Stopwatch stopwatch = Stopwatch.StartNew();

            var exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
            {
                Credentials = new WebCredentials(credentials.UserName, credentials.Password),
                Timeout     = 60000
            };

            exchangeService.AutodiscoverUrl(
                credentials.EmailAddress,
                x =>
            {
                Logger.Debug($"Following redirection for EWS autodiscover: {x}");
                return(true);
            }
                );

            Logger.Debug($"Service URL: {exchangeService.Url}");

            EWSConnection ewsConnection = default(EWSConnection);

            try
            {
                EWSMailFolder ewsMailFolder           = new EWSMailFolder(Folder.Bind(exchangeService, WellKnownFolderName.Inbox));
                RecipientsMailboxManagerRouter router = new RecipientsMailboxManagerRouter(ewsMailFolder);

                ewsConnection = new EWSConnection
                {
                    Service = exchangeService,
                    Router  = router
                };
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to connect to EWS", ex);
            }

            stopwatch.Stop();
            logger.LogSampledMetric("EWSConnectTime", stopwatch.ElapsedMilliseconds, "milliseconds");

            return(ewsConnection);
        }
示例#2
0
        private EWSConnection ConnectToEWS(Credentials credentials)
        {
            Logger.Debug($"Initializing FolderMailboxManager for email address {credentials.EmailAddress}");
            Stopwatch stopwatch = Stopwatch.StartNew();

            var exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1)
            {
                Credentials = new WebCredentials(credentials.UserName, credentials.Password),
                Timeout = 60000
            };

            exchangeService.AutodiscoverUrl(
                credentials.EmailAddress,
                x =>
                {
                    Logger.Debug($"Following redirection for EWS autodiscover: {x}");
                    return true;
                }
                );

            Logger.Debug($"Service URL: {exchangeService.Url}");

            EWSConnection ewsConnection = default(EWSConnection);
            try
            {
                EWSMailFolder ewsMailFolder = new EWSMailFolder(Folder.Bind(exchangeService, WellKnownFolderName.Inbox));
                RecipientsMailboxManagerRouter router = new RecipientsMailboxManagerRouter(ewsMailFolder);

                ewsConnection = new EWSConnection
                {
                    Service = exchangeService,
                    Router = router
                };
            }
            catch (Exception ex)
            {
                Logger.Error("Failed to connect to EWS", ex);
            }

            stopwatch.Stop();
            logger.LogSampledMetric("EWSConnectTime", stopwatch.ElapsedMilliseconds, "milliseconds");

            return ewsConnection;
        }