<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog - PonticStar.com &#187; ASP.NET</title>
	<atom:link href="http://www.ponticstar.com/blog/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ponticstar.com/blog</link>
	<description>Blog about various aspects of programming and web design</description>
	<lastBuildDate>Sun, 14 Aug 2011 23:52:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sending an e-mail with ASP.NET and System.Net.Mail via Google</title>
		<link>http://www.ponticstar.com/blog/2009/04/23/sending-email-with-asp-net/</link>
		<comments>http://www.ponticstar.com/blog/2009/04/23/sending-email-with-asp-net/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 22:06:46 +0000</pubDate>
		<dc:creator>Michael Ryvkin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.ponticstar.com/blog/?p=32</guid>
		<description><![CDATA[Few days ago I needed to develop contact form handler for the website hosted on Windows platform. JavaScript and AJAX were used on the client side to send request to the server. After some reading about ASP.NET framework it become clear that I need to write custom handler (.ashx) to process this request. In the [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I needed to develop contact form handler for the website hosted on Windows platform. JavaScript and AJAX were used on the client side to send request to the server. After some reading about ASP.NET framework it become clear that I need to write custom handler (.ashx) to process this request. <span id="more-32"></span></p>
<p>In the example below Google is used as e-mail service provider. If you have Google Apps account replace <code>username@gmail.com</code> with your e-mail address including domain name.</p>
<p><strong>send_inquiry.ashx</strong>:</p>
<pre class="brush:csharp"><%@ WebHandler Language="C#" class="ContactFormHandler" %>

using System;
using System.Web;
using System.Net.Mail;

public class ContactFormHandler : IHttpHandler {

   public void ProcessRequest (HttpContext context) {

       SmtpClient smtp  = new SmtpClient();
       smtp.Host        = "smtp.gmail.com";
       smtp.Port        = 587; // or 465
       smtp.EnableSsl   = true;
       smtp.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");

       MailMessage msg = new MailMessage();
       msg.From = new MailAddress("username@gmail.com");
       msg.To.Add("To@address.com");
       msg.Subject = "Web site inquiry";

       // Additional options
       // msg.IsBodyHtml   = true;
       // msg.BodyEncoding = Encoding.UTF8;
       // msg.Priority     = MailPriority.High;

       string strName    = context.Request.Form["name"];
       string strEmail   = context.Request.Form["email"];
       string strPhone   = context.Request.Form["phone"];
       string strMessage = context.Request.Form["message"];

       string strBody = "";
       strBody += "Name:   " + strName  + "\n";
       strBody += "E-mail: " + strEmail + "\n";
       strBody += "Phone:  " + strPhone + "\n";
       strBody += "Message:\n" + strMessage + "\n";

       msg.Body = strBody;

       context.Response.ContentType = "text/plain";
       try {
          smtp.Send(msg);
          context.Response.Write("Success");

       } catch (Exception e) {
          context.Response.Write("Failure (" + e.ToString() + ")"); ;
       }

       msg.Dispose();
   }

   public bool IsReusable {
       get {
           return false;
       }
   }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ponticstar.com/blog/2009/04/23/sending-email-with-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

