Introduction
This article explains a simple Email formatter framework. This would enable programmers to extend/implement custom email formatter classes. This in conjunction with an Email Publisher class can be very useful for web applications,smart client applications and windows services to format and send emails. We have several articles and code snippetts for publishing emails but none for formatting emails. This sample, abstracts out email formatting part and later integrates it into an Email Publisher class.
IEmailFormatter interface
IEmailFormatter interface defines the contract for the framework. All formatter classes have to implement this contract. <v:stroke joinstyle="miter"><v:path o:connecttype="rect" gradientshapeok="t">
<o:p>Concrete class MQExceptionFormatter
<o:p>
Class MQExceptionEmailFormatter, A concrete class which implements this interface. This class helps formatting email message for a MSMQ message.
<o:p>
<o:p>Similarly different formatter classes can be implemented according to the need by implementing the interface.
<o:p>Implement FormatMessage() function to format an email
<o:p>following piece of code shows a sample implementation of the FormatMessage() function by the MQExceptionEmailFormatter class.
<o:p>
<o:p> If the email format is standardized then we could implement an abstract Email Formatter class having a default implementation for the FormatMessage() function and have all the other concrete formatter classes extend this abstract class.
<o:p> Class EmailPublisher using IEmailFormatter types
<o:p> Class EmailPublisher now uses IEmailFormatter type in it's implementation and hence can use any of the IEmailFormatter concrete classes to access email subject and Email body.
<o:p>
<o:p> SendMail...
The SendMail Function internally accesses formatting information from the formatter classes.
Sample Usage
<o:p>
A Certified .NET MCSD (Microsoft Certified Solution Developer)that specializes in Microsoft technologies architecting/designing/developing applications using .NET (C# or VB), ASP.NET, SQL Server and BizTalk.
I have contributed as a designer/developer for benchmarked products in the finance industry benchmarked for best transaction engine design and products that offer end to end solution to research based content. Currently working with UMASS Medical School at Worcester MA.
Hobbies include music,reading books and playing cricket.