public EmailNotificationAdapter(string emailServiceEndpoint, string emailSvcUserAccount, string emailSvcUserPassword, string emailSvcUserDomain)
        {
            if (string.IsNullOrWhiteSpace(emailServiceEndpoint))
            {
                throw new ArgumentException("Service end point must not be null or whitespace.", nameof(emailServiceEndpoint));
            }

            if (string.IsNullOrWhiteSpace(emailSvcUserAccount))
            {
                throw new ArgumentException("User account must not be null or whitespace.", nameof(emailSvcUserAccount));
            }

            if (string.IsNullOrWhiteSpace(emailSvcUserPassword))
            {
                throw new ArgumentException("User assword must not be null or whitespace.", nameof(emailSvcUserPassword));
            }

            if (string.IsNullOrWhiteSpace(emailSvcUserDomain))
            {
                throw new ArgumentException("User domain must not be null or whitespace.", nameof(emailSvcUserDomain));
            }

            exchangeSvc = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2013)
            {
                Url         = new Uri(emailServiceEndpoint),
                Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(emailSvcUserAccount, emailSvcUserPassword, emailSvcUserDomain)
            };
        }
        public object CreateMessage(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, string toMail)
        {
            Microsoft.Exchange.WebServices.Data.ExchangeService service = new Microsoft.Exchange.WebServices.Data.ExchangeService();
            service = ClientOutlookSvcPoint.GetInstance.CreateExchangeService();

            Microsoft.Exchange.WebServices.Data.EmailMessage message = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);
            int maxLengthMailSubject = EmailProperties.GetInstance.MailSubjectMaxLength;

            mailSubject = mailBody.Length > maxLengthMailSubject
             ? mailSubject.Substring(0, maxLengthMailSubject) + "...." : mailSubject;

            message.Subject = mailSubject;
            message.ToRecipients.Add(toMail);
            Microsoft.Exchange.WebServices.Data.MessageBody messageBody = new Microsoft.Exchange.WebServices.Data.MessageBody();
            messageBody.BodyType = isBodyHTML?Microsoft.Exchange.WebServices.Data.BodyType.HTML: Microsoft.Exchange.WebServices.Data.BodyType.Text;
            messageBody.Text     = mailBody;
            return(message);
        }
        private string EnviaEmail(string emailRem, string senhaRem, string emailDest, string assunto, string corpo)
        {
            try
            {
                var service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2013_SP1);
                service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(emailRem, senhaRem);
                service.AutodiscoverUrl(emailRem);
                var email = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);
                email.Subject = assunto;
                email.Body    = corpo;
                email.ToRecipients.Add(emailDest);
                email.SendAndSaveCopy();

                return("Justificativa enviada com sucesso para aprovação !");
            }
            catch (Exception)
            {
                return("Ocorreu algum erro ao tentar enviar o email !");
            }
        }
        private string EnviaEmail(string emailRem, string senhaRem, string emailDest, string assunto, StringBuilder corpo)
        {
            try
            {
                var service = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2013_SP1);
                service.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(emailRem, senhaRem);
                service.AutodiscoverUrl(emailRem);
                var email = new Microsoft.Exchange.WebServices.Data.EmailMessage(service);
                email.Subject = assunto;
                email.Body    = corpo.ToString();
                email.ToRecipients.Add(emailDest);
                email.SendAndSaveCopy();

                return("E-mail enviado com sucesso !");
            }
            catch (Exception ex)
            {
                return("Ocorreu algum erro, " + ex);
            }
        }
        public async Task SendEmailWithVerificationCode(Object json)
        {
            string name;
            string username;

            SprHuman[] sprHuman;
            dynamic    jsonDynamic = JObject.Parse(json.ToString());
            //if (!CheckOutGoogleRecaptchaToken(jsonDynamic.captcha.ToString()))
            //{
            //    await Response.WriteAsync("Is invalid recaptcha token !");
            //    return;
            //}
            AutodiscoverRedirectionUrlValidationCallback autodiscoverRedirectionUrlValidationCallback = (string redirectionUrl) => { Uri redirectionUri = new Uri(redirectionUrl); if (redirectionUri.Scheme == "https")
                                                                                                                                     {
                                                                                                                                         return(true);
                                                                                                                                     }
                                                                                                                                     else
                                                                                                                                     {
                                                                                                                                         return(false);
                                                                                                                                     } };

            Microsoft.Exchange.WebServices.Data.ExchangeService exchangeService = new Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2013_SP1);
            exchangeService.Credentials = new Microsoft.Exchange.WebServices.Data.WebCredentials(AuthorizationConfig.login, AuthorizationConfig.password);
            try
            {
                string   email    = jsonDynamic.email;
                DateTime birthday = DateTime.Parse(jsonDynamic.birthdate.ToString());
                sprHuman = GetInformationFromDatabase(email);
                if (birthday != sprHuman[0].Birthday)
                {
                    await Response.WriteAsync($"Email is doesn't send !");

                    return;
                }
                name     = $"{sprHuman[0].FirstName} {sprHuman[0].LastName}";
                username = sprHuman[0].SamaccountName;
                Random random           = new Random();
                string verificationCode = AuthorizationConfig.verificationCode;
                for (int i = 0; i <= 10; i++)
                {
                    char   characterLetter = (char)random.Next('A', 'Z');
                    char   characterDigit  = (char)random.Next('1', '9');
                    char[] characters      = { characterLetter, '~', '!', characterDigit, '@', '#', characterLetter, '$', '&', characterDigit, '*', '(', characterLetter, ')', '_', characterDigit, '+', '?', characterLetter, ':', '-', characterDigit, '=', ',', characterLetter, '.', ';', characterDigit, '[', ']', characterLetter };
                    verificationCode += $"{characters[random.Next(characters.Length)]}";
                }
                verificationCodes.Add(verificationCode, username);
                exchangeService.Timeout = 300000;
                exchangeService.AutodiscoverUrl(AuthorizationConfig.login, autodiscoverRedirectionUrlValidationCallback);
                ThreadStart threadStart = () => { Action action = () => { Thread.Sleep(300000); verificationCodes.Remove(verificationCodes[verificationCode]); }; };
                Thread      thread      = new Thread(threadStart);
                thread.Start();
                Microsoft.Exchange.WebServices.Data.EmailMessage emailMessage = new Microsoft.Exchange.WebServices.Data.EmailMessage(exchangeService);
                emailMessage.ToRecipients.Add(email);
                emailMessage.Subject = "Hello World";
                emailMessage.Body    = new Microsoft.Exchange.WebServices.Data.MessageBody($"Hello {name} ! This is the verification code {verificationCode} which you must to introduce in following link http://elk-test.iep.ru/password-reset/{GenerateToken(username, AuthorizationConfig.lifeTimeForCheckOutEmailOrChangePasswordForUnauthUser)}");
                await emailMessage.SendAndSaveCopy();

                await Response.WriteAsync("Email is sent !");
            }
            catch (Exception ex)
            {
                await Response.WriteAsync($"Email is doesn't send ! {ex.Message}");
            }
        }