tag:blogger.com,1999:blog-6450910739204323292024-03-08T08:50:25.068-08:00Metal ThoughtDocumenting the occasional single thought that runs through my mind.
By: Eyal Mey-TalUnknownnoreply@blogger.comBlogger5125tag:blogger.com,1999:blog-645091073920432329.post-47402636672359135172010-03-27T05:30:00.001-07:002010-03-28T05:57:30.572-07:00Configuring your HTC HD2 Leo email account to use Wi-FiIf you've read any of my posts, you probably know I'm not one to shy of Microsoft's technology. So, when it came to buying a smart phone I went for the best Hardware available - even if it means using Window Mobile as my my OS. Getting the best HW these days means the <a href="http://www.amazon.com/HTC-Unlocked-Smartphone-Camera-Windows/dp/B0030MHQXO?ie=UTF8&tag=metalt-20&link_code=btl&camp=213689&creative=392969" target="_blank">HTC HD2 Leo</a><img alt="" border="0" height="1" src="http://www.assoc-amazon.com/e/ir?t=metalt-20&l=btl&camp=213689&creative=392969&o=1&a=B0030MHQXO" style="border: medium none ! important; margin: 0px ! important; padding: 0px ! important;" width="1" /><br />
So, from time to time I'll post some tips here.<br />
<br />
If you want your email account to use Wi-Fi in order to send/receive your mail (instead of the expensive GPRS default) - do this:<br />
<br />
Start >> E-mail >> [select your account] >> Menu Options >> [select your account from the list (yea I know you did that in the previous step)] >> Edit Account Setup >>Next >> Next >> Next >> Next >> Advanced Server Settings >> In Network Connection select "The Internet" >> Done >> Next >> Next >> Finish<br />
<br />
That's a well hidden configuration wouldn't you say?Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-645091073920432329.post-14923445371883535222010-03-15T13:35:00.000-07:002010-03-28T05:58:43.119-07:00Enabling incompatible add-ons in Firefox 3.6It may be so 2008, but, I do love my Firefox with my choice selection of add-ons. That's why I was dismayed to find out that Firefox 3.6 has caused quite a few of them to be disabled due to incompatibility.<br />
Today, I got tired of waiting for the new releases, so I decided to enable incompatible add-ons - I recalled doing it when I switched to version 3 by using the old <b>extensions.checkCompatibility. </b>This <a href="http://www.raymond.cc/blog/archives/2008/10/29/enable-firefox-incompatible-add-ons-and-this-add-on-is-for-older-versions-of-firefox/">post </a>used to be a big help.<br />
<br />
It seems however, that the semi-official way of doing this in Firefox 3.6 is by installing the "<a href="https://addons.mozilla.org/en-US/firefox/addon/15003">add-on compatibility reporter</a>".<br />
<br />
If you would like to allow incompatible add-ons in Firefox 3.6 without installing this additional plugin, you now need to add the version name to the preference name, like so; <b>extensions.checkCompatibility.{version}</b>. Check out the Mozzila documentation <a href="http://kb.mozillazine.org/Extensions.checkCompatibility">here</a>.<br />
<br />
So, to summarize if you want to bypass Firefox's compatibility checking and allow your favorite add-ons to run.<br />
<ul><li>Type <b>about:config</b> into Firefox’s address bar and click the “I’ll be careful, I promise!” button.</li>
<li>Right-click anywhere in the list and select <b>New</b> > <b>Boolean</b>.</li>
<li> Type <b>extensions.checkCompatibility.3.6</b> and click OK.</li>
<li> Select <b>false</b> and click OK.</li>
<li>Restart your browser.</li>
</ul>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-645091073920432329.post-37721226537939834102009-05-12T14:44:00.001-07:002009-06-27T13:53:00.965-07:00Enhanced performance for the ASP.NET AJAX autocomplete control<h5> </h5> <h5>The Problem </h5> <p>AutoComplete controls have become a main feature in many interactive website and web applications.</p> <p>In fact it is very common to explain the advantages of AJAX using the “Google Suggest” example, as this was one of the first powerful well known implementations implementations.</p> <p>Microsoft has provided a very powerful and easy to use control in the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Default.aspx" target="_blank">ASP .NET AJAX Control Toolkit</a> – the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx" target="_blank">AutoCompleteExtender</a>.</p> <p>There are two approaches to creating AutoComplete controls. The first one is to transmit all possible data to the client, and implement the algorithm that suggests possible completions, in the browser using JavaScript. The other approach is to send an AJAX request to the server that will retrieve a list of suggested completion words. Such a request is being made every time a new prefix is entered in the AutoComplete text box.</p> <p>The AutoCompleteExtender is implemented using the second approach – this approach works best when the vocabulary that needs to be considered for suggestions is potentially very large – this would make it impractical to download the full list of possibility to the client.</p> <p>When you implement an AutoCompleteExtender you need to provide a web service that will be used to supply the word/sentence completions. But, the guide and sample stop there and do not instruct you how to build an effective web service.</p> <p>You need to consider that such a web service is used in a highly interactive way, and may need to respond quickly to the waiting user by suggesting completions from a potentially large database. Furthermore each user is likely to make several such completion requests within a short period of time. If you intend to support many concurrent users, you have a potential load problem on your hands.</p> <p>The trivial implementation for such a web service would select from the DB your data and convert it to a string array, there are quite a few such examples on the web, here’s a raw snippet for the service method:</p> <div style="width: 450px;" class="codeframe"> <pre class="csharpcode">[WebMethod]<br /><span class="kwrd">public</span> <span class="kwrd">string</span>[] GetStudentNames(<span class="kwrd">string</span> prefix)<br />{ <br /><span class="kwrd">string</span> sql = <span class="str">"SELECT * from students WHERE name like @prefix"</span>;<br /><br />...<br /><br /><span class="kwrd">string</span>[] items = <span class="kwrd">new</span> <span class="kwrd">string</span>[dt.Rows.Count];<br /><span class="kwrd">int</span> i = 0;<br /><span class="kwrd">foreach</span> (DataRow dr <span class="kwrd">in</span> dt.Rows)<br />{<br /> items.SetValue(dr[<span class="str">"name"</span>].ToString(), i);<br /> i++;<br />}<br /><span class="kwrd">return</span> items;<br />} </pre><br /></div><br /><br /><p>The problem with the above code is that it will access the DB to retrieve and filter the required data every time the user will change the prefix in the the AutoComplete control. This puts unnecessary strain on both your DB server and the web server and will severely degrade the performance if the amount of data involved is large.</p>The common solution for unnecessary DB trips is caching, but here we encounter another problem – what is it that we need to cache and how?<br /><br /><p>In the above example we could potentially select all student names in the DB and cache that as a list in memory – but when the method is called we will need to filter only those names that start with the required prefix. A naive implementation will go over the whole list and check each string against the prefix (with a complexity of O(n) where n is the number of student names in the DB), but there are more appropriate data structures to handle this problem.</p><br /><br /><h5>The Solution</h5><br /><p>One of the best data structures to handle this problem is the <a href="http://en.wikipedia.org/wiki/Trie" target="_blank">Trie</a>.</p><br /><p>A .NET Trie implementation that is specifically tailored to serve the AutoCompleteExtender can be downloaded from CodePlex <a href="http://datastructures.codeplex.com/" target="_blank">here</a>.</p><br /><p>The time complexity of building a Trie is considered to be O(n) where n is the total amount of strings to be contained in the Trie. To search for the existence of a prefix we need O(l) where l is the length of the prefix.</p><br /><p>Retrieving a list of strings beginning with the prefix – is done at O(m) where m is the number of strings that will be retrieved.</p><br /><p>You should consider that querying the DB, and building a large Trie can be costly in time and memory. But once the Trie is built you can cache it and use it repeatedly for fast search and string completions. Specifically, you can use a cached Trie to repeatedly return string suggestions from the AutoComplete web service.</p><br /><h5>How To Use</h5><br /><p>First <a href="http://datastructures.codeplex.com/Release/ProjectReleases.aspx">download </a>the code from CodePlex.</p><br /><p>Follow the regular instructions on how to use the <a href="http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx" target="_blank">AutoCompleteExtender</a>.</p><br /><p>Make sure your web service builds the AutoCompletion Trie and stores it in cache, if it does not already exist. If and when it does exist use it to return the completion list:</p><br /><br /><div style="width: 450px;" class="codeframe"><br /><br /><br /><pre class="csharpcode"> [WebMethod]<br /><span class="kwrd">public</span> <span class="kwrd">string</span>[] GetCustomers(<span class="kwrd">string</span> prefixText, <span class="kwrd">int</span> count)<br />{<br /> Trie customersTrie = (Trie)Context.Cache[<span class="str">"CustomersTrie"</span>];<br /> <span class="kwrd">if</span> (customersTrie == <span class="kwrd">null</span>)<br /> {<br /> customersTrie = <span class="kwrd">new</span> Trie();<br /> customersTrie.Load(<span class="str">"Donald Duck"</span>);<br /> customersTrie.Load(<span class="str">"Duffy Duck"</span>);<br /> customersTrie.Load(<span class="str">"Mini Mouse"</span>);<br /> customersTrie.Load(<span class="str">"Mickey Mouse"</span>);<br /> customersTrie.Load(<span class="str">"Pluto Dog"</span>);<br /> customersTrie.Load(<span class="str">"Guffy Dog"</span>);<br /> Context.Cache[<span class="str">"CustomersTrie"</span>] = customersTrie;<br /> }<br /> List<<span class="kwrd">string</span>> list = customersTrie.FindCompletions(prefixText);<br /> <span class="kwrd">return</span> list.ToArray();<br />}</pre><br /></div><br /><br /><p> </p><br /><p>Note that the Trie is thread safe for multiple readers only. You should protect the Trie from concurrent read/write operations.</p><br /><p>Check out the code and unit tests for some further details, to run the unit tests you will need <a href="http://www.nunit.org/" target="_blank">NUnit</a>. If you want to run the performance test you will need an external dictionary you can use the AGID wordlist from: <a href="http://wordlist.sourceforge.net/">http://wordlist.sourceforge.net/</a> or modify the code to use a different large word list.</p><br />Here are some posts I have found helpful while building this Trie:<br /><a href="http://sujitpal.blogspot.com/2007/02/three-autocomplete-implementations.html">http://sujitpal.blogspot.com/2007/02/three-autocomplete-implementations.html</a><br /><a href="http://rmandvikar.blogspot.com/2008/07/tries.html">http://rmandvikar.blogspot.com/2008/07/tries.html</a><br /><a href="http://rmandvikar.blogspot.com/2008/10/trie-examples.html">http://rmandvikar.blogspot.com/2008/10/trie-examples.html</a><br /><br /><br /><br /><p>Share & Enjoy.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-645091073920432329.post-1451655732841363382009-04-02T01:58:00.001-07:002009-04-02T04:02:21.145-07:00Containing Child Controls inside a UserControl<p>User Controls are a very quick and effective method to develop reusable controls for your application. They are usually much easier to develop than writing your own custom server controls.</p> <p>I ran into a situation the other day that a user control we’ve made and had been working on for some time, just got a new requirement to be able to contain child server controls. I was a bit surprised to discover this is not a trivial matter.</p> <p>It seems there is a weird limitation on User controls. If you try to put child controls in them or nest a user control inside another, the designer will complain. Furthermore if you thought you could use the PersistChildrenAttribute in order to convince the designer that your control is really intended to support this behavior, then think again – it seems that the designer simply ignores this possibility when it comes to user controls.</p> <p>While searching for a solution, I discovered <a href="http://www.csharper.net/blog/container_user_controls___user_controls_that_can_contain_other_controls.aspx" target="_blank">this post</a> by Bobby DeRosa that suggested a reasonable solution. The problem with this solution is that you get XHTML validation errors. However, a comment in the post suggests a better solution.</p> <p>While a Container User Control is not directly supported, a <a href="http://msdn.microsoft.com/en-us/library/36574bf6.aspx" target="_blank">templated user control</a> is supported by Microsoft.</p> <p>And so, the below suggested solution will work nicely. Just to make things more interesting I made the sample control support two areas that can contain child controls; a header section and a content section. </p> <p>The User Control’s code behind looks like this:</p> <pre><p><span style="color:blue;">public partial class </span><span style="color: rgb(43, 145, 175);">ContainerUserControl </span>: <span style="color: rgb(43, 145, 175);">UserControl<br /></span>{<br />[<span style="color: rgb(43, 145, 175);">PersistenceMode</span>(<span style="color: rgb(43, 145, 175);">PersistenceMode</span>.InnerProperty)]<br /><span style="color:blue;"> public</span><span style="color: rgb(43, 145, 175);">ITemplate </span>Header { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }<br /><br />[<span style="color: rgb(43, 145, 175);">PersistenceMode</span>(<span style="color: rgb(43, 145, 175);">PersistenceMode</span>.InnerProperty)]<br /><span style="color:blue;"> public</span><span style="color: rgb(43, 145, 175);">ITemplate </span>Content { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }<br /><br /><span style="color:blue;"> protected override void</span>OnInit(<span style="color: rgb(43, 145, 175);">EventArgs </span>e)<br />{<br /><span style="color:blue;"> base</span>.OnInit(e);<br /> Content.InstantiateIn(ContentPlaceHolder);<br /> Header.InstantiateIn(HeaderPlaceHolder);<br />}<br />}</p></pre> <a href="http://11011.net/software/vspaste"></a> <p>While the markup should have a place holder for each section that will contain child elements:</p><br /><pre> <p><span style="background: rgb(255, 238, 98) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><%</span><span style="color:blue;">@</span><span style="color: rgb(163, 21, 21);">Control</span><span style="color:red;">Language</span><span style="color:blue;">="C#"</span><span style="color:red;">AutoEventWireup</span><span style="color:blue;">="true"</span><span style="color:red;">CodeBehind</span><span style="color:blue;">="ContainerUserControl.ascx.cs"</span><span style="color:red;">Inherits</span><span style="color:blue;">="TestWebApp.ContainerUserControl"</span><span style="background: rgb(255, 238, 98) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">%><br /></span><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">><br /><</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">PlaceHolder </span><span style="color:red;">ID</span><span style="color:blue;">="HeaderPlaceHolder"</span><span style="color:red;">runat</span><span style="color:blue;">="server"><br /></</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">PlaceHolder</span><span style="color:blue;">><br /><br /><</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">PlaceHolder </span><span style="color:red;">ID</span><span style="color:blue;">="ContentPlaceHolder"</span><span style="color:red;">runat</span><span style="color:blue;">="server"><br /></</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">PlaceHolder</span><span style="color:blue;">><br /></</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">></span></p> <p> </p></pre> <p>And here is a sample of the usage:</p> <pre> <p><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">form </span><span style="color:red;">id</span><span style="color:blue;">="form1" </span><span style="color:red;">runat</span><span style="color:blue;">="server"><br /><</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">><br /><</span><span style="color: rgb(163, 21, 21);">uc</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">ContainerUserControl </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ID</span><span style="color:blue;">="OuterContainer"><br /> <</span><span style="color: rgb(163, 21, 21);">Header</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">Label </span><span style="color:red;">ID</span><span style="color:blue;">="Label1" </span><span style="color:red;">Text</span><span style="color:blue;">="Main label" </span><span style="color:red;">runat</span><span style="color:blue;">="server" /><br /> </</span><span style="color: rgb(163, 21, 21);">Header</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">Content</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">Button </span><span style="color:red;">ID</span><span style="color:blue;">="btnTest" </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">Text</span><span style="color:blue;">="Test me" /><br /> </</span><span style="color: rgb(163, 21, 21);">Content</span><span style="color:blue;">><br /></</span><span style="color: rgb(163, 21, 21);">uc</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">ContainerUserControl</span><span style="color:blue;">><br /></</span><span style="color: rgb(163, 21, 21);">div</span><span style="color:blue;">><br /></</span><span style="color: rgb(163, 21, 21);">form</span><span style="color:blue;">><br /></span></p> </pre> <p>You can even nest a user control inside another user control:</p> <pre><p><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">uc</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">ContainerUserControl </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">ID</span><span style="color:blue;">="OuterContainer"><br /><</span><span style="color: rgb(163, 21, 21);">Header</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">Label </span><span style="color:red;">ID</span><span style="color:blue;">="Label1" </span><span style="color:red;">Text</span><span style="color:blue;">="Main label" </span><span style="color:red;">runat</span><span style="color:blue;">="server" /><br /></</span><span style="color: rgb(163, 21, 21);">Header</span><span style="color:blue;">><br /><</span><span style="color: rgb(163, 21, 21);">Content</span><span style="color:blue;">> <br /> <</span><span style="color: rgb(163, 21, 21);">uc</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">ContainerUserControl </span><span style="color:red;">ID</span><span style="color:blue;">="InnerContainer" </span><span style="color:red;">runat</span><span style="color:blue;">="server"><br /> <</span><span style="color: rgb(163, 21, 21);">Header</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">Label </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">Text</span><span style="color:blue;">="Nested label"/><br /> </</span><span style="color: rgb(163, 21, 21);">Header</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">Content</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">h2</span><span style="color:blue;">></span>This is a nested content<span style="color:blue;"></</span><span style="color: rgb(163, 21, 21);">h2</span><span style="color:blue;">><br /> </</span><span style="color: rgb(163, 21, 21);">Content</span><span style="color:blue;">><br /> </</span><span style="color: rgb(163, 21, 21);">uc</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">ContainerUserControl</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">asp</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">Button </span><span style="color:red;">ID</span><span style="color:blue;">="btnTest" </span><span style="color:red;">runat</span><span style="color:blue;">="server" </span><span style="color:red;">Text</span><span style="color:blue;">="Test me" /><br /></</span><span style="color: rgb(163, 21, 21);">Content</span><span style="color:blue;">><br /></</span><span style="color: rgb(163, 21, 21);">uc</span><span style="color:blue;">:</span><span style="color: rgb(163, 21, 21);">ContainerUserControl</span><span style="color:blue;">></span></p> </pre> <p>One more point to remember is that because the designer does not really support the inner content of the user control, you will not be able to refer directly to controls such as the above button. The reason is that the generated aspx.designer.cs will not include the inner controls as they are a part of the template. Therefore you will need code such as this to refer to the button:</p> <p><span style="color:blue;">this</span>.OuterContainer.FindControl(<span style="color: rgb(163, 21, 21);">"btnTest"</span>);</p> <a href="http://11011.net/software/vspaste"></a> <p>Hopefully this will save you some time developing a full blown server control.</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-645091073920432329.post-6522349270887149372009-03-17T18:13:00.001-07:002009-04-30T15:02:15.618-07:00SSL must not be enabled for pickup-directory delivery methods<p>Maybe I'm just getting soft and lazy.<br />It seems I've gotten used to just finding the answer to everything I need by googling it and relying on the community to solve it for me.</p> <p>I mean, at least when I’m not dealing with the bleeding edge of technology, I should expect to find a post from somebody who’s already ran into a similar problem – right?</p> <p>Well, I was a bit surprised when I tried to implement a simple email client using the totally mundane System.Net.Mail (really not bleeding edge, is it?), and received the following exception:</p> <p>“<b>SSL must not be enabled for pickup-directory delivery methods</b>“</p> <p>Happily I searched the web for this error message only to find two (2!) whole articles about it, none of which was any help at all.</p> <p>So, I figured it’s a good enough reason for my first blog post. After all, the blog itself has been ready and waiting for several months now for me to find the time and motivation to write something.</p> <p>But, I was doing something <u>really</u> trivial - there must be thousands of blog posts about how to write an SMTP client to send mail using the <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx"><span style="color: rgb(43, 145, 175);">SmtpClient</span> </a>class.</p> <p>The code itself goes something like this:</p><div class="codeframe"><pre class="csharpcode"><span style="color: rgb(43, 145, 175);">MailMessage </span>emailMessage = <span style="color:blue;">new </span><span style="color: rgb(43, 145, 175);">MailMessage</span>();<br />emailMessage.From = from;<br /><span style="color:blue;">foreach </span>(<span style="color: rgb(43, 145, 175);">MailAddress </span>ma <span style="color:blue;">in </span>to)<br />emailMessage.To.Add(ma);<br />emailMessage.Subject = subject;<br />emailMessage.Body = message;<br /><br /><span style="color: rgb(43, 145, 175);">SmtpClient </span>smtp = <span style="color:blue;">new </span><span style="color: rgb(43, 145, 175);">SmtpClient</span>(_smtpHost, 587);<br /><br />smtp.UseDefaultCredentials = <span style="color:blue;">false</span>;<br />smtp.Credentials = <span style="color:blue;">new </span>System.Net.<span style="color: rgb(43, 145, 175);">NetworkCredential</span>(<span style="color: rgb(163, 21, 21);">"myGmailAccount"</span>, <span style="color: rgb(163, 21, 21);">"myGmailPassword"</span>);<br />smtp.EnableSsl = <span style="color:blue;">true</span>;<br />smtp.Send(emailMessage);</pre></div><br /><p>A textbook sample, isn’t it?</p><p>As it turns out, the error is really self explanatory if you you’re aware of the <span style="color: rgb(43, 145, 175);">SmtpClient</span>‘s <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.deliverymethod.aspx">DeliveryMethod </a>Property and its usage.</p><pre class="code"></pre><p>But I wasn’t messing with the DeliveryMethod - so why would it mess with me?</p><p>It took me a while to find out that someone has left a surprise for me in the web.config: </p><pre class="code"><span style="color:blue;"><</span><span style="color: rgb(163, 21, 21);">system.net</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">mailSettings</span><span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">smtp </span><span style="color:red;">deliveryMethod</span><span style="color:blue;">=</span>"<span style="color:blue;">PickupDirectoryFromIis</span>"<span style="color:blue;">><br /> <</span><span style="color: rgb(163, 21, 21);">network </span><span style="color:red;">defaultCredentials</span><span style="color:blue;">=</span>"<span style="color:blue;">true</span>" <span style="color:red;">host</span><span style="color:blue;">=</span>"<span style="color:blue;">localhost</span>" <span style="color:red;">port</span><span style="color:blue;">=</span>"<span style="color:blue;">25</span>"<span style="color:blue;">/><br /> </</span><span style="color: rgb(163, 21, 21);">smtp</span><span style="color:blue;">><br /> </</span><span style="color: rgb(163, 21, 21);">mailSettings</span><span style="color:blue;">><br /></</span><span style="color: rgb(163, 21, 21);">system.net</span><span style="color:blue;">></span></pre><br /><p>And while I was overriding all the other parameters in my code, the DeliveryMethod was defaulting to PickupDirectoryFromIis, which is obviously incompatible with SSL (it makes perfect sense actually, if you’re going to write the emails to a queue directory on your file system, then you obviously won’t need to be using SSL).</p><p>If you want to know more about DeliveryMethod you may find Marco’s <a href="http://www.dotnet2themax.com/blogs/mbellinaso/PermaLink,guid,081e87cc-d3b4-4ba4-a1cc-f49fc701a7ee.aspx">post</a> useful.</p><p>The solution for me was to just get rid of the whole configuration section. I’m one of the people who think MS has messed up implementing the default configuration system, and it really shouldn’t be used for anything more complicated then switching between your own environments. If you use web.config or app.config to actually manage real configuration parameters that change between different installations then you’re in a world of pain. But I digress.</p><p>On the other hand, some other parts of the framework such as the ASP.NET membership controls rely on this configuration section. So if you don’t want to face the consequences of taking away a piece of configuration that may be used elsewhere in the system, then you can explicitly override the DeliveryMethod in your code like this:</p><pre class="code">smtp.DeliveryMethod = SmtpDeliveryMethod.Network;</pre><p>I hope this has made things a bit clearer regarding the usage of DeliveryMethod and its pitfalls.</p><a href="http://11011.net/software/vspaste"></a>Unknownnoreply@blogger.com6