public async Task <IActionResult> SubmitInquireForm(InquireFormViewModel inquireForm) { var client = new SmtpClient(); var credentials = new NetworkCredential { UserName = "******", Password = config.GetValue <string>("SendGridAPIKey") }; client.Credentials = credentials; client.Host = "smtp.sendgrid.net"; client.Port = 25; var email = new MailMessage(); email.To.Add(new MailAddress(config.GetValue <string>("InquireEmail"))); email.From = new MailAddress("*****@*****.**"); email.Subject = "Website Inquiry"; email.IsBodyHtml = true; email.Body = ComposeBody(inquireForm); client.Send(email); return(NoContent()); }
private string ComposeBody(InquireFormViewModel inquireForm) { var body = new StringBuilder(); body.Append("<html>"); body.Append("<body>"); body.Append("<div>"); body.Append("<h2>HCC Website Inquiry</h2>"); body.Append("<table border=0 cellspacing=0 cellpadding=0>"); body.Append(AddRow("First Name", inquireForm.FirstName)); body.Append(AddRow("Middle Name", inquireForm.MiddleName)); body.Append(AddRow("Last Name", inquireForm.LastName)); var address = string.Empty; if (!string.IsNullOrEmpty(inquireForm.Street) && !string.IsNullOrEmpty(inquireForm.City) && !string.IsNullOrEmpty(inquireForm.State) && !string.IsNullOrEmpty(inquireForm.ZipCode)) { address = inquireForm.Street + "<br />"; address += inquireForm.City + ", " + inquireForm.State + " " + inquireForm.ZipCode; } body.Append(AddRow("Address", address)); body.Append(AddRow("Home Phone", inquireForm.HomePhone)); body.Append(AddRow("Cell Phone", inquireForm.MobilePhone)); body.Append(AddRow("Email", inquireForm.EmailAddress)); if (inquireForm.HasChildren && inquireForm.Children.Count > 0) { var childTable = new StringBuilder(); childTable.Append("<table border=1 cellspacing=0 cellpadding=0 width=600>"); childTable.Append("<tr>"); childTable.Append(" <td width=265 valign=top style='padding:0in 5.4pt 0in 5.4pt'>"); childTable.Append(" <b>Name</b>"); childTable.Append(" </td>"); childTable.Append(" <td width=85 valign=top style='padding:0in 5.4pt 0in 5.4pt'>"); childTable.Append(" <b>DOB</b>"); childTable.Append(" </td>"); childTable.Append(" <td width=162 valign=top style='padding:0in 5.4pt 0in 5.4pt'>"); childTable.Append(" <b>School</b>"); childTable.Append(" </td>"); childTable.Append(" <td width=72 valign=top style='padding:0in 5.4pt 0in 5.4pt'>"); childTable.Append(" <b>Grade</b>"); childTable.Append(" </td>"); childTable.Append("</tr>"); foreach (var child in inquireForm.Children) { childTable.Append(AddChildren(child)); } childTable.Append("</table>"); body.Append(AddRow("Children", childTable.ToString())); } if (inquireForm.TalkToPastor) { body.Append(AddRow("Talk to Fr Paul", "Yes")); body.Append(AddRow("Best Time to Call", inquireForm.BestTimeDay)); } if (inquireForm.Interests.Count > 0) { var interests = string.Empty; foreach (var interest in inquireForm.Interests) { interests += interest + "<br />"; } if (!string.IsNullOrEmpty(interests)) { body.Append(AddRow("Interested In", interests)); } } if (!string.IsNullOrEmpty(inquireForm.HeardHow)) { if (inquireForm.HeardHow.Equals("Other") && !string.IsNullOrEmpty(inquireForm.HeardHowOther)) { body.Append(AddRow("Heard About From", inquireForm.HeardHowOther)); } else { body.Append(AddRow("Heard About From", inquireForm.HeardHow)); } } if (!string.IsNullOrEmpty(inquireForm.Comments)) { body.Append("<tr>"); body.Append(" <td width=772 colspan=2 valign=top style='padding:0in 5.4pt 0in 5.4pt'>"); body.Append(" <b>Questions/Comments</b>"); body.Append(" </td>"); body.Append("</tr>"); body.Append("<tr>"); body.Append(" <td width=772 colspan=2 valign=top style='padding:0in 5.4pt 0in 5.4pt'>"); body.Append(inquireForm.Comments); body.Append(" </td>"); body.Append("</tr>"); } body.Append("</table>"); body.Append("</div>"); body.Append("</body>"); body.Append("</html>"); return(body.ToString()); }