Esempio n. 1
0
 public HttpResponseMessage EmailTrocaSMTP(UpdateSmtpViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var envioEmail = new EnvioEmail(_ServerConfigRepo);
             var domainName = Request.RequestUri.Scheme + "://" + Request.RequestUri.Host;
             envioEmail.EmailTrocaSMTP(domainName, model.SmtpAdress, model.SmtpPort, model.SmtpUsername, model.SmtpPassword);
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
         else
         {
             var errorObj = ModelStateErrors.DisplayModelStateError(ModelState);
             return(Request.CreateResponse(HttpStatusCode.NotAcceptable, errorObj, "text/plain"));
         }
     }
     catch (SmtpException ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Não foi possível authenticar este email, verifique sua senha e as configurações."));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
 public ActionResult SMTP(UpdateSmtpViewModel model)
 {
     if (ModelState.IsValid)
     {
         HttpContent form = new FormUrlEncodedContent(new[] {
             new KeyValuePair <string, string>("SmtpAdress", model.SmtpAdress),
             new KeyValuePair <string, string>("SmtpPort", model.SmtpPort.ToString()),
             new KeyValuePair <string, string>("SmtpUsername", model.SmtpUsername),
             new KeyValuePair <string, string>("SmtpPassword", model.SmtpPassword)
         });
         var res = ApiAnalista.EmailTrocaSMTP(form);
         if (res.IsSuccessStatusCode)
         {
             Session.Add("trocaSMTP", model);
             return(View(model));
         }
         else
         {
             var result = res.Content.ReadAsStringAsync().Result;
             ModelState.AddModelError("error", result);
             return(View(model));
         }
     }
     else
     {
         return(View(model));
     }
 }