<?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>Vishal Kumar &#187; asp</title>
	<atom:link href="http://www.vishalkumar.in/tag/asp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vishalkumar.in</link>
	<description>Think Different. Make a Difference.</description>
	<lastBuildDate>Thu, 24 Nov 2011 15:54:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Asp.NET Mail using Gmail SMTP Tutorial</title>
		<link>http://www.vishalkumar.in/2009/06/aspnet-mail-using-gmail-smtp-tutorial/</link>
		<comments>http://www.vishalkumar.in/2009/06/aspnet-mail-using-gmail-smtp-tutorial/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 20:17:22 +0000</pubDate>
		<dc:creator>Vishal</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[gmail]]></category>

		<guid isPermaLink="false">http://www.vishalkumar.in/?p=157</guid>
		<description><![CDATA[A tutorial on sending Asp.NET email using GMail's SMTP.]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s very useful to learn how to set up to send mail using Asp.NET, both GMail and Asp.NET are widely used and trusted. One advantage is flexibility: If you&#8217;re a setting up a large email system for mass mail-outs to <a href="http://www.foxybingo.com/" target="_blank">Foxy Bingo</a> customers and other gaming fans, or if you&#8217;re a smaller, family business who is just mailing your local clientele, this system is up to the job. Enjoy the tutorial.</p>
<p>So here is another, even briefer, tutorial on sending mail in Asp.NET using GMail SMTP (means using a GMail Account doh!).<br />
<span id="more-157"></span></p>
<p>Alright, this is what you do:</p>
<ol>
<li>If you haven&#8217;t done so already, download a .NET development tool like <a href="http://www.microsoft.com/exPress/download/#webInstall">Visual Web Developer 2008 Express Edition</a>.</li>
<li>Go to File&gt;New Web Site, select new ASP.NET Web Site, and choose Visual C# for your language. (Ok, You&#8217;ve mostly probably already come up to this stage, but I&#8217;m just being complete. <img src='http://www.vishalkumar.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<div id="attachment_158" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.vishalkumar.in/wp-content/uploads/2009/06/screenshot-6_10_2009-11_49_11-pm.png"><img class="size-medium wp-image-158" title="Screenshot of New Web Site" src="http://www.vishalkumar.in/wp-content/uploads/2009/06/screenshot-6_10_2009-11_49_11-pm-300x193.png" alt="Step 2 in action. If you are not seeing this, try harder." width="300" height="193" /></a><p class="wp-caption-text">Step 2 in action. If you are not seeing this, try harder.</p></div>
<ol>
<li>Now, by default you&#8217;ll see your Default.aspx file, where you can use the visual tools to drag and drop in your files. But you actually want the Default.aspx.cs file to edit. On the right you&#8217;ll see your Solution Explorer. Click on the plus and double click on Default.aspx.cs</li>
</ol>
<div id="attachment_159" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.vishalkumar.in/wp-content/uploads/2009/06/screenshot-6_10_2009-11_54_01-pm.png"><img class="size-medium wp-image-159" title="Screenshot of Visual Web Developer 2008 Express" src="http://www.vishalkumar.in/wp-content/uploads/2009/06/screenshot-6_10_2009-11_54_01-pm-300x187.png" alt="Top right, Solution Explorer. Code in the middle." width="300" height="187" /></a><p class="wp-caption-text">Top right, Solution Explorer. Code in the middle.</p></div>
<ol>
<li>Here you&#8217;ll have the actual C# code that runs to generate your HTML output for the browser. So this is where you shall put in your C# Mail code. Be sure to edit out like the username (your entire GMail gmail), and password (you know, that one).</li>
</ol>
<pre>using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        sendMail();
    }
    public void sendMail()
    {
        string from="vishalkumar@gmail.com";
        string to = "vishalkumar@gmail.com";
        string subject = "Hi there";
        string body = "Hey there &lt;br /&gt; Check out http://www.vishalkumar.in";
        sendMailall(from, to, subject, body);
    }
    public void sendMailall(string from, string to, string subject, string body)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(to);
        mail.From = new MailAddress(from);
        mail.Subject = subject;
        mail.Body = body;
        mail.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Credentials =
             new System.Net.NetworkCredential("vishalkumar@gmail.com",
                                                                "thisisnotmypassword");
        smtp.EnableSsl = true;
        smtp.Send(mail);
     }
}</pre>
<ol>
<li>Now just press F5 to debug, which basically means run the page. By simply running the above page, you&#8217;ll trigger the code to send an email to the address specified.</li>
<li>And you&#8217;re done for now. You can now add extra features like creating a form, or sending automated emails, etc, for all you like. Enjoy.</li>
</ol>
<p>And thats it. Alright I admit, you didn&#8217;t really need that many steps. Frankly, just copy the code and play with it.</p>
<p>If you get stuck (and you tried really really hard yes please), gmail me later. Or comment up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vishalkumar.in/2009/06/aspnet-mail-using-gmail-smtp-tutorial/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

