Created
October 27, 2017 09:51
-
-
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.**
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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