Exemple #1
1
        private static void CatchEmails()
        {
            string login = ConfigurationManager.AppSettings["login"];
            string pass = ConfigurationManager.AppSettings["pass"];
            string mail = ConfigurationManager.AppSettings["mail"];
            WebCredentials credentials = new WebCredentials(mail, pass);
            //Client.Credentials = new WebCredentials(login, pass);
            Client.Credentials = credentials;
            Client.UseDefaultCredentials = false;
            Client.AutodiscoverUrl(mail, RedirectionUrlValidationCallback);

            ItemView view = new ItemView(1000000000);//Чтобы ничего не пропустить берем миллиард записей сразу ))

            FindItemsResults<Item> findResults = Client.FindItems(WellKnownFolderName.Inbox, view);

            if (findResults.Any())
            {
                Client.LoadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
                bool send = HolidayWork.CheckTodayIsPreHoliday().SendDelivery;

                foreach (Item item in findResults.Items)
                {
                    if (send)
                    {
                        if (item.Subject.Contains("Автоматический ответ:")) continue;
                        string fullName = item.LastModifiedName;
                        if (fullName.Equals("Microsoft Outlook")) continue;

                        Objects.ResponseMessage responseMessage;
                        bool complete = Confirmation.Save(fullName, out responseMessage);
                        //if (!complete) throw new Exception(responseMessage.ErrorMessage);

                        if (DateTime.Now.Hour < 16 || (DateTime.Now.Hour == 16 && DateTime.Now.Minute <= 3))
                        {
                            if (complete)
                            {
                                item.Delete(DeleteMode.SoftDelete);
                                Confirmation.SendNote(responseMessage.Email);
                            }
                            else
                            {
                                Confirmation.SendError(responseMessage.Email);
                            }
                        }
                        else if (DateTime.Now.Hour > 16)
                        {
                            item.Delete(DeleteMode.SoftDelete);
                            Confirmation.SendEndTime(responseMessage.Email);
                        }
                        else
                        {
                            Confirmation.SendError(responseMessage.Email);
                        }
                    }
                    else
                    {
                        item.Delete(DeleteMode.SoftDelete);
                    }
                }
            }
        }
Exemple #2
0
        public void StreamingExchange()
        {
            try
            {
                Stopwatch watch;
                long elapsedMs = 0;

                watch = Stopwatch.StartNew();

                _logger.LogInformation(string.Format(LogsProcess.InitProcess, Variables.StreamingExchange, DateTime.Now.ToString()));

                Exchange.ExchangeService service = new Exchange.ExchangeService(Exchange.ExchangeVersion.Exchange2013);
                Exchange.WebCredentials wbcred = new Exchange.WebCredentials(
                    _parametersProcessum.GeracaoArquivoEmail.Login,
                    _parametersProcessum.GeracaoArquivoEmail.Senha);

                service.Credentials = wbcred;
                service.AutodiscoverUrl(_parametersProcessum.GeracaoArquivoEmail.Login, EWSConnection.RedirectionUrlValidationCallback);

                EWSConnection.SetStreamingNotifications(service, resetEvent, _parametersProcessum);

                resetEvent.WaitOne();

                watch.Stop();

                elapsedMs = watch.ElapsedMilliseconds;

                _logger.LogInformation(string.Format(LogsProcess.FinishProcess, Variables.StreamingExchange, DateTime.Now.ToString()));
                _logger.LogInformation(string.Format(LogsProcess.TimeExecution, Variables.StreamingExchange, elapsedMs.ToString()));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public string StandardConnectionToInHouseExchanges(string username, string password, string url, string domain = null)
        {
            try
            {
                //Try each exchange version until the correct one is found
                string VersionResponse = null;
                ConnectionConfig serviceConfig = new ConnectionConfig();
                WebCredentials credentials;
                if (domain == null)
                {
                     credentials = new WebCredentials(username, password);
                }
                else
                {
                     credentials = new WebCredentials(username, password, domain);
                }
                Uri URL = new Uri(url);

                service = new ExchangeService(ExchangeVersion.Exchange2013);
                service.Credentials = credentials;
                service.Url = URL;
                string foundVersion = GetExchangeVersion("2013", service);
                VersionResponse = foundVersion;
                if (foundVersion != "" && foundVersion != "404" && foundVersion != "401") return foundVersion;

                service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
                service.Credentials = credentials;
                service.Url = URL;
                foundVersion = GetExchangeVersion("2010_SP2", service);
                VersionResponse = foundVersion;
                if (foundVersion != "" && foundVersion != "404" && foundVersion != "401") return foundVersion;

                service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Credentials = credentials;
                service.Url = URL;
                foundVersion = GetExchangeVersion("2010_SP1", service);
                VersionResponse = foundVersion;
                if (foundVersion != "" && foundVersion != "404" && foundVersion != "401") return foundVersion;

                service = new ExchangeService(ExchangeVersion.Exchange2010);
                service.Credentials = credentials;
                service.Url = URL;
                foundVersion = GetExchangeVersion("2010", service);
                VersionResponse = foundVersion;
                if (foundVersion != "" && foundVersion != "404" && foundVersion != "401") return foundVersion;

                service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = credentials;
                service.Url = URL;
                foundVersion = GetExchangeVersion("2007_SP1", service);
                VersionResponse = foundVersion;
                if (foundVersion != "" && foundVersion != "404" && foundVersion != "401") return foundVersion;

                return VersionResponse;

            }
            catch (Exception ex)
            {
                // Debug.DebugMessage(2, "Error in Test Connection2: " + ex.Message);
               // MessageBox.Show("Error in Test Connection: " + ex.Message, "Test Connection");
                return "null";
            }

            return null;
        }