Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 09:51
Show Gist options
  • Save ps-team/0ad98ac59726b3aae7477dcad04f453e to your computer and use it in GitHub Desktop.
Save ps-team/0ad98ac59726b3aae7477dcad04f453e to your computer and use it in GitHub Desktop.
Send an email to an email address using the EmailHost set against the publisher. You could create a text box called #MyFormFieldName with this to allow a user to enter details. @using System.Net.Mail; **This method is not necessarily best practice, we should discuss other options for posting emails.**
@using Contensis.Framework.Web;
@using System.Net.Mail;
@if (IsPost) {
string EmailFrom = "[email protected]";
string EmailTo = "[email protected]";
MailMessage email = new MailMessage();
email.IsBodyHtml = true;
string emailBody = "";
emailBody += "<p>" + Request.Form["MyFormFieldName"] + "</p>";
email.Subject = "Test email sent from Razor";
email.Body = "<div>" + emailBody + "</div>";
email.To.Add(new MailAddress(EmailTo));
email.From = new MailAddress(EmailFrom);
SmtpClient client = new SmtpClient(CMS_API.Navigation.NavigationProviderFactory.GetNavigationProvider(CMS_API.Navigation.NavigationProviderType.Xml).EmailHost);
try {
client.Send(email);
} catch (Exception exc) {
Response.Write(exc);
}
}
<button id="SubmitJobChoice" class="sys_btn sys_btn--nextbtn" type="submit">
Send message
</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment