<%@ WebHandler Language="C#" Class="xMail" %>
using System;
using System.Web;
using System.Xml;
using System.Xml.XPath;
using System.Net.Mail;
using System.IO;
public class xMail : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string strMessageBody = "";
//Create an instance of the MailMessage class
try
{
// XPath is clean, simple, and likely to last for many years as an XML parsing standard
// The following code creates a .NET object for parsing the incoming XML message using the XPath language
XPathDocument xpathdocument = new XPathDocument(context.Request.InputStream);
XPathNavigator xpathnavigator = xpathdocument.CreateNavigator();
// This is how we build an email message body that will likely be presented using HTML
strMessageBody = "Name: " + xpathnavigator.SelectSingleNode("//Name").Value + "
";
strMessageBody += "Email: " + xpathnavigator.SelectSingleNode("//Email").Value + "
";
strMessageBody += "Phone: " + xpathnavigator.SelectSingleNode("//Phone").Value + "
";
strMessageBody += "Comments: " + xpathnavigator.SelectSingleNode("//Comments").Value;
MailMessage objMM = new MailMessage();
MailAddress objToAddress = new MailAddress("xreceiver@sqlajax.com");
MailAddress objFromAddress = new MailAddress("xsender@sqlajax.com", "Joe Sender");
MailAddress objCCAddress = new MailAddress("xcc@sqlajax.com");
objMM.To.Add(objToAddress);
objMM.CC.Add(objCCAddress);
objMM.Sender = objFromAddress;
objMM.From = objFromAddress;
////email format. Can be Text or Html
objMM.IsBodyHtml = true;
////Set the priority - options are High, Low, and Normal
objMM.Priority = MailPriority.Normal;
////Set the subject
objMM.Subject = "New feedback from hhs-days.com";
////Set the body
objMM.Body = strMessageBody;
////Smtp Server
System.Net.Mail.SmtpClient smtpServer = new SmtpClient("mysmtp.sample.net");
////Send the message
smtpServer.Send(objMM);
}
catch (Exception e)
{
context.Response.Write(e.Message);
}
}
public bool IsReusable {
get {
return false;
}
}
}