// EmailAddress is valid then send mail . // return "success" or error public async Task <ActionResult> ProcessSubmittedEmail(string name, string emailId, string message) { string result = ""; try { EmailAddressDO emailAddressDO = new EmailAddressDO(emailId); RegexUtilities.ValidateEmailAddress(_configRepository, emailAddressDO.Address); using (IUnitOfWork uow = ObjectFactory.GetInstance <IUnitOfWork>()) { _emailAddress.ConvertFromMailAddress(uow, new MailAddress(emailId, name)); string toRecipient = _configRepository.Get("CustomerSupportEmail"); string fromAddress = emailId; string subject = "Customer query"; await _email.SendAsync(uow, subject, message, fromAddress, toRecipient); uow.SaveChanges(); } result = "success"; } catch (ValidationException ex) { result = "You need to provide a valid Email Address."; Logger.GetLogger().Warn("Invalid email provided: " + emailId); } catch (Exception ex) { result = "Something went wrong with our effort to send this message. Sorry! Please try emailing your message directly to [email protected]"; Logger.GetLogger().Error($"Error processing a home page email form submission. Name = {name}; EmailId = {emailId}; Exception = {ex}"); } return(Content(result)); }
// EmailAddress is valid then send mail . // return "success" or error public ActionResult ProcessSubmittedEmail(string name, string emailId, string message) { string result = ""; try { EmailAddressDO emailAddressDO = new EmailAddressDO(emailId); RegexUtilities.ValidateEmailAddress(emailAddressDO.Address); using (IUnitOfWork uow = ObjectFactory.GetInstance <IUnitOfWork>()) { _emailAddress.ConvertFromMailAddress(uow, new MailAddress(emailId, name)); string toRecipient = "*****@*****.**"; string fromAddress = emailId; // EmailDO emailDO = email.GenerateBasicMessage(emailAddressDO, message); string subject = "Customer query"; _email.Send(uow, subject, message, fromAddress, toRecipient); //uow.EnvelopeRepository.ConfigurePlainEmail(emailDO); uow.SaveChanges(); } result = "success"; } catch (ValidationException) { result = "You need to provide a valid Email Address."; } catch (System.Exception ex) { result = "Something went wrong with our effort to send this message. Sorry! Please try emailing your message directly to [email protected]"; Logger.GetLogger().Error("Error processing a home page email form submission.", ex); } return(Content(result)); }