Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Doing Email Testing in development without an Exchange Server, II


I talked about my home office Exchange server crashing in a September post and how I came up with an approach to test HTML-based email components without requiring an Exchange Server. I needed to re-create this functionality on a different project today since I still haven't re-installed Exchange (and don't want to until I absolutely have to!) The result is that HTML emails are sent to web folder for viewing in IE rather than sent to Exchange for viewing in Outlook.

This is a snap when you've implemented a single Email component which is used for your entire application. If that's the case, the lines where (if you did have an exchange server) you previously set the local SmtpMail.SmtpServer property you now send out the message to your need MailToFile() class.

if (ConfigurationSettings.AppSettings["Environment].ToString().IndexOf("dev") > 0)
{
 imsii.Utils.MailToFile.Send(msg);
}
else
{
 SmtpMail.SmtpServer = "";
 SmtpMail.Send(msg);
}


The small MailToFile.cs class is located here, with the essence of the thing being to create a filestream to write the email message to file.


string s = msg.To.Substring(1, msg.To.IndexOf("@") -1);
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("/dump/mail/" +
 FileTimeString() + s + ".htm"), FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.BaseStream.Seek(0, SeekOrigin.Begin);
sw.Write(msg.Body + "\r\n");
sw.WriteLine("<ul><b>TO:</b>  " + msg.To + "<br>");
sw.WriteLine("<b>Subject:</b>  " + msg.Subject + "</ul><p></p>");
sw.Close();
return true;

With folder browsing enabled, an IE window lists the output files for viewing.


 

Comments (2) | Post RSS RSS comment feed

Posted on 11/3/2004 11:05:00 AM by Dave Burke
Categories: .NET
Tags:

Related posts

Comments (2) -

4/4/2007 7:54:28 PM Permalink

Excellent. Don't know why I didn't think about this before.

Denis |

4/4/2007 7:59:58 PM Permalink

Great to hear it, Denis.  Yeap, comes in pretty handy.

daveburke |


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke