Exemple #1
0
        // url is domainname/mail/send
        // ModelBinding is underlying here for getting the ContractFormData as a parameter
        public ActionResult Send(ContactFormData model)
        {
            if (ModelState.IsValid)
            {
                var smtpServer = string.IsNullOrEmpty(ConfigurationManager.AppSettings["smtpServer"]) ? "smtp.zonnet.nl" : ConfigurationManager.AppSettings["smtpServer"];
                var usernameSmtp = ConfigurationManager.AppSettings["usernameSmtp"];
                var passwordSmtp = ConfigurationManager.AppSettings["passwordSmtp"];

                var smtpClient = string.IsNullOrEmpty(usernameSmtp) ? new Emailer(smtpServer) : new Emailer(smtpServer, usernameSmtp, passwordSmtp, true);

                var resultModel = new MailResultModel { ResultMessage = string.Empty, Succeeded = true };
                var useCaseContext = new ContactFormSubmitContext(model, new Emailer(smtpServer), resultModel);

                useCaseContext.Execute();

                return View("ContactMailSent", resultModel);
            }
            return View("Contact", model);
        }
 public ContactFormSubmitContext(SubmitModel data, EmailSender mailer, MailResultModel result)
 {
     this.Data = data;
     this.Emailer = mailer;
     this.Result = result;
 }