<?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>freemind blogs &#187; asp.net</title>
	<atom:link href="http://blogs.freemind.net/index.php/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.freemind.net</link>
	<description></description>
	<lastBuildDate>Thu, 19 Nov 2009 04:49:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using Email Templates With ASP.NET</title>
		<link>http://blogs.freemind.net/index.php/using-email-templates-with-aspnet/31/</link>
		<comments>http://blogs.freemind.net/index.php/using-email-templates-with-aspnet/31/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 21:41:33 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://blogs.freemind.net/?p=31</guid>
		<description><![CDATA[Somedays working with ASP.NET can be a treat. Especially on those days when you stumble upon some functionality you had no idea existed. It seems like every website has some need to generate emails for things like order confirmation, password resets, or news updates. System.Net.Mail provides excellent functionality for building email messages and communicating with [...]]]></description>
			<content:encoded><![CDATA[<p>Somedays working with ASP.NET can be a treat. Especially on those days when you stumble upon some functionality you had no idea existed.</p>
<p>It seems like every website has some need to generate emails for things like order confirmation, password resets, or news updates. System.Net.Mail provides excellent functionality for building email messages and communicating with SMTP servers. But it is up to the developer to build the actual content of the message programmatically, usually by using a StringBuilder to concatenate a bunch of user-specific and common strings.</p>
<p>Turns out there is class and technique that can simplify that code quite a bit. MailDefinition is a class that allows you to build email templates and easily update the dynamic parts. </p>
<p>Check out the following code:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> GenerateOrderEmailCustomer<span style="color: #008000;">&#40;</span>Order order<span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF; font-weight: bold;">try</span><br />
&nbsp; &nbsp;<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; MailDefinition template <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> MailDefinition<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; template<span style="color: #008000;">.</span><span style="color: #0000FF;">BodyFileName</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;~/templates/CustomerOrderConfirmation.html&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; template<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">From</span> <span style="color: #008000;">=</span> order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Retailer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationConfig</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EmailOrderFromAddress</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span> data <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.OrderNumber&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">OrderNumber</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Store.Name&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Status&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Status</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.FirstName&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">FirstName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.LastName&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">LastName</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Address1&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Address1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Address2&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Address2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.City&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">City</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.State&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">State</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Zip&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Zip</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.PaymentMethod&gt;&gt;&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">PaymentMethod</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Payment.CardHoldersName&gt;&gt;&quot;</span>, <span style="color: #008000;">&#40;</span>order<span style="color: #008000;">.</span><span style="color: #0000FF;">Payment</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> order<span style="color: #008000;">.</span><span style="color: #0000FF;">Payment</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CardHoldersName</span><span style="color: #008000;">:</span><span style="color: #666666;">&quot;n/a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Payment.CardType&gt;&gt;&quot;</span>, <span style="color: #008000;">&#40;</span>order<span style="color: #008000;">.</span><span style="color: #0000FF;">Payment</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">?</span> order<span style="color: #008000;">.</span><span style="color: #0000FF;">Payment</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CardType</span><span style="color: #008000;">:</span><span style="color: #666666;">&quot;n/a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Payment.CreditCardNumber&gt;&gt;&quot;</span>, <span style="color: #008000;">&#40;</span>order<span style="color: #008000;">.</span><span style="color: #0000FF;">Payment</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">?</span> order<span style="color: #008000;">.</span><span style="color: #0000FF;">Payment</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CreditCardNumber</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Substring</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">4</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; **** **** ****&quot;</span> <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;n/a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> detailTable <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>OrderDetail detail <span style="color: #0600FF; font-weight: bold;">in</span> order<span style="color: #008000;">.</span><span style="color: #0000FF;">Details</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;detailTable <span style="color: #008000;">+=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;tr&gt;&lt;td&gt;{0}&lt;/td&gt;&lt;td&gt;{1}&lt;/td&gt;&lt;/tr&gt;&quot;</span>, detail<span style="color: #008000;">.</span><span style="color: #0000FF;">Quantity</span>, detail<span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;order.Details&gt;&gt;&quot;</span>, detailTable<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; data<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;&lt;url&gt;&gt;&quot;</span>, <span style="color: #666666;">&quot;http://www.wineconnect.com/&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; MailMessage message <span style="color: #008000;">=</span> template<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateMailMessage</span><span style="color: #008000;">&#40;</span>order<span style="color: #008000;">.</span><span style="color: #0000FF;">Email</span>, data, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> LiteralControl<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; message<span style="color: #008000;">.</span><span style="color: #0000FF;">IsBodyHtml</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; message<span style="color: #008000;">.</span><span style="color: #0000FF;">Subject</span> <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Order Confirmation: {0} ({1})&quot;</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Name</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">OrderNumber</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; SmtpClient client <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SmtpClient<span style="color: #008000;">&#40;</span>order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Retailer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationConfig</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EmailServer</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Retailer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationConfig</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EmailPort</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//Enable SSL</span><br />
&nbsp; &nbsp; &nbsp; client<span style="color: #008000;">.</span><span style="color: #0000FF;">EnableSsl</span> <span style="color: #008000;">=</span> order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Retailer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationConfig</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EmailEnableSsl</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; client<span style="color: #008000;">.</span><span style="color: #0000FF;">UseDefaultCredentials</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; client<span style="color: #008000;">.</span><span style="color: #0000FF;">Credentials</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> NetworkCredential<span style="color: #008000;">&#40;</span>order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Retailer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationConfig</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EmailUsername</span>, order<span style="color: #008000;">.</span><span style="color: #0000FF;">Store</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Retailer</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ApplicationConfig</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EmailPassword</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; client<span style="color: #008000;">.</span><span style="color: #0000FF;">SendCompleted</span> <span style="color: #008000;">+=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SendCompletedEventHandler<span style="color: #008000;">&#40;</span>MailDeliveryComplete<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; client<span style="color: #008000;">.</span><span style="color: #0000FF;">SendAsync</span><span style="color: #008000;">&#40;</span>message, message<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp;<span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception ex<span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; _log<span style="color: #008000;">.</span><span style="color: #0000FF;">Error</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Error caught while sending customer order confirmation&quot;</span>, ex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp;<span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Combined with this template:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span>Order Confirmation<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/title.html"><span style="color: #000000; font-weight: bold;">title</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">table</span></a> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> bordercolor<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;EDF5E3&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">tr</span></a> <span style="color: #000066;">bgcolor</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#999999&quot;</span> &gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;center&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;height: 16px&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a> <span style="color: #000066;">color</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#FFFFFF&quot;</span>&gt;</span>Order Confirmation (<span style="color: #009900;">&lt;&lt;order.OrderNumber&gt;</span>&gt;)<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">span</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">tr</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">tr</span></a>&gt;&lt;<a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;&lt;order.FirstName&gt;</span>&gt;,<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
This email confirms your order: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Store: <span style="color: #009900;">&lt;&lt;order.Store.Name&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Order Status: <span style="color: #009900;">&lt;&lt;order.Status&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span>Billing Information: <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Customer: <span style="color: #009900;">&lt;&lt;order.FirstName&gt;</span>&gt; <span style="color: #009900;">&lt;&lt;order.LastName&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Address1: <span style="color: #009900;">&lt;&lt;order.Address1&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Address2: <span style="color: #009900;">&lt;&lt;order.Address2&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
City: <span style="color: #009900;">&lt;&lt;order.City&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
State: <span style="color: #009900;">&lt;&lt;order.State&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Zip: <span style="color: #009900;">&lt;&lt;order.Zip&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span>Payment Method: <span style="color: #009900;">&lt;&lt;order.PaymentMethod&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Card Holder: <span style="color: #009900;">&lt;&lt;order.Payment.CardHoldersName&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Card Type: <span style="color: #009900;">&lt;&lt;order.Payment.CardType&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Card Number: <span style="color: #009900;">&lt;&lt;order.Payment.CreditCardNumber&gt;</span>&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Order Information:<br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">table</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;messageTxt&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">tr</span></a>&gt;&lt;<a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;</span>Qty.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;&lt;<a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;</span>Item<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">tr</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;&lt;order.Details&gt;</span>&gt;<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">table</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a><span style="color: #66cc66;">/</span>&gt;</span><br />
Your order number is <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">strong</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'&lt;&lt;url&gt;</span></span>&gt;/OrderSummary.aspx?OrderNumber=<span style="color: #009900;">&lt;&lt;order.OrderNumber&gt;</span>&gt;'&gt;<span style="color: #009900;">&lt;&lt;order.OrderNumber&gt;</span>&gt;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">strong</span></a>&gt;</span>.<br />
Please feel free to contact us with any questions or visit our website if you need directions to our store.<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;&lt;url&gt;</span></span>&gt;&quot;&gt;<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">strong</span></a>&gt;&lt;&lt;url&gt;</span>&gt;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">strong</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span><br />
Thank you,<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;</span>Wine Store Dudes<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">br</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">td</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">tr</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">table</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div>
<p>It generates this email:</p>
<p><a href="http://blogs.freemind.net/wp-content/uploads/2008/07/croppercapture431.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" title="CropperCapture[43]" src="http://blogs.freemind.net/wp-content/uploads/2008/07/croppercapture43-thumb.jpg" border="0" alt="CropperCapture[43]" width="388" height="518" /></a></p>
<p><strong>Good Stuff:</strong></p>
<p>Using this technique I was able to get rid of a bunch of string concatenation and string.Format code. The template should be much easier to maintain going forward.</p>
<p><strong>Lame:</strong></p>
<p>The way MailDefinition replaces the dynamic tokens is nice but a bit limiting. It might be fun to try using a Server.Execute method to pick up other ASP.NET goodness like data binding and advanced logic.</p>
<p>The CreateMailMessage function also requires a OwnerControl to be passed in. They could have given us an overloaded version that didn’t require this because I doubt anyone ever uses it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.freemind.net/index.php/using-email-templates-with-aspnet/31/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
