Tuesday, May 16, 2006

System.Net.Mail.MailDefinition

Ok, not a big deal here, but something I rather liked. I wanted to create a generic way to pull an email template, replace key areas with standard things like first name, company information, and other details and a coworker let me know about the .net password recovery control that does something similar. After digging in a bit, I found that it was using the MailDefinition to invoke a CreateMailMessage passing in the collection of replacements.

It was very nice not to have to write the find/replace code (even though that would be simple). There are still a few steps left to wrap the email templates table, but the basics are there to the point that we can toss a new template in a table and execute replacements on it to send some notification email messages to our clients.

One gotcha, I kept running into the following error:


Unable to read data from the transport connection: net_io_connectionclosed.


As it turned out, my particular issue here was that relay was turned off on our email server for all clients. In short, I had to open a hole to allow a certain server to access the smpt server in order to send the email.