Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Simple Email Formatter Framework - Using C#, Smtp

0.00/5 (No votes)
6 Jun 2006 1  
This article explains a simple Email formatter framework in conjunction with an EmailPublisher class to format and send email messages.

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. 

 IEmailFormatter    

Concrete class MQExceptionFormatter

Class MQExceptionEmailFormatter, A concrete class which implements this interface. This class helps formatting email message for a MSMQ message. 

 

  MQExceptionEmailFormatter.jpg

Similarly different formatter classes can be implemented according to the need by implementing the interface.

Implement FormatMessage() function to format an email

following piece of code shows a sample implementation of the FormatMessage() function by the MQExceptionEmailFormatter class.

 Implement_FormatMessage_function.jpg

  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.

 Class EmailPublisher using IEmailFormatter types

 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.

 PublishEmail.jpg

 SendMail...

The SendMail Function internally accesses formatting information from the formatter classes.

PublishEmail

Sample Usage

 Usage1.jpg

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here