Skip to content

Instantly share code, notes, and snippets.

@rbaty-barr
Last active January 30, 2017 17:43
Show Gist options
  • Save rbaty-barr/80ef9869cfe878a1bddf2635e4c65588 to your computer and use it in GitHub Desktop.
Save rbaty-barr/80ef9869cfe878a1bddf2635e4c65588 to your computer and use it in GitHub Desktop.
starting point for custom form sending
@using System.Net.Mail;
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
string comments = Request["comments"];
string pageID = Request["theID"];
if(Request.Headers["X-Requested-With"] == "XMLHttpRequest"){
var pageNode = Umbraco.TypedContent(pageID.ToString());
MailMessage message = new MailMessage();
string fromEmail = "";
message.From = new MailAddress(fromEmail);
message.To.Add(new MailAddress(fromEmail));
message.Bcc.Add(new MailAddress(""));
message.Subject = "Anon Feedback";
message.Body = "<table border='0' cellpadding='20' cellspacing='0' width='600' align='center' style='font-family:Helvetica,Arial,sans-serif;'><tr><td>";
message.Body = message.Body + "<h1>Website feedback from sidebar form</h1>";
message.Body = message.Body + "<p><strong>Comments: </strong>" + comments + "<br/>";
message.Body = message.Body + "<strong>Page: </strong>" + pageNode.Url + "</p>";
message.Body = message.Body + "</td></tr></table>";
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential("", "");
client.Port = 587;
client.Host = "smtp.gmail.com";
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = basicCredential;
client.EnableSsl = true;
//message.ReplyToList.Add(userName);
client.Send(message);
<p>Mail Sent</p>
} else {
<p>YO! you cannot send thought this form</p>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment