public async Task <ActionResult> ContactUsSubmission(ContactUsViewModel contactUs) { ViewBag.ModelState = ModelState; if (ModelState.IsValid) { var emailReference = GenerateEmailReference(contactUs); ViewBag.EmailReference = emailReference; try { var placeholders = new Dictionary <string, dynamic> { { "EmailReference ", emailReference }, { "Name", FormFieldSanitizer.SanitizeFormField(contactUs.Name) }, { "Email", FormFieldSanitizer.SanitizeFormField(contactUs.Email) }, { "SchoolTrustName", FormFieldSanitizer.SanitizeFormField(contactUs.SchoolTrustName) ?? "N/A" }, { "Message", contactUs.Message } }; await _emailSender.SendContactUsUserEmailAsync(contactUs.Email, placeholders); await _emailSender.SendContactUsDfEEmailAsync(ConfigurationManager.AppSettings["SRMEmailAddress"], placeholders); } catch (HttpRequestValidationException exc) { var enableAITelemetry = WebConfigurationManager.AppSettings["EnableAITelemetry"]; if (enableAITelemetry != null && bool.Parse(enableAITelemetry)) { var ai = new TelemetryClient(); ai.TrackException(exc); ai.TrackTrace($"Contact us email rejected due to SQL injection attack!"); ai.TrackTrace($"Contact us email sending failed for: {contactUs.Name} - ({contactUs.SchoolTrustName}) ({contactUs.Email}) - ref: {emailReference}"); } throw exc; } catch (Exception exception) { var enableAITelemetry = WebConfigurationManager.AppSettings["EnableAITelemetry"]; if (enableAITelemetry != null && bool.Parse(enableAITelemetry)) { var ai = new TelemetryClient(); ai.TrackException(exception); ai.TrackTrace($"Contact us email sending error: {exception.Message}"); ai.TrackTrace($"Contact us email sending failed for: {contactUs.Name} ({contactUs.Email}) - ref: {emailReference}"); } throw; } return(View("ContactUsConfirmation")); } else { return(View("index", contactUs)); } }