Home
Download

NetEmailer Component for .Net 2.0 User Guide

System requirement: .Net 2.0 framework
The latest version is 1.2 and you can download the sample code with the NetEmailer.dll here.

Quite often an application has bunch of emails to send out, account request email, account approve/deny notification, users' actions notification, etc. We don't want to hard coded the email content or the recipients' email address, it really should be a templates that can be maintained by non-IT person and changed without recompiling the application. Meanwhile, some dynamic information like the username, user email address, current datetime, etc. should be inserted to the template during runtime. NetEmailer can do all this for you. It is a SMTP component for the creation and sending of e-mail messages in .Net. Written in pure C#, NetEmailer is fully managed. It is totally object oriented and easy to use.  Best of all, all emails are based on templates. In another word, every single part of the email, from the recipients' list to the email body is totally configurable in a xml file; and dynamic content can be inserted at runtime.

Follow the steps below to start using NetEmailer:

1.     reference NetEmailer.dll in your project;

2.     import the NetEmailer and NetEmailer.TokenMapping namespace;

3.     create a emailer configuration file similar to the following one(Don’t forget to change the smtpServer setting and the email address):

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <!--CodeBlock can be used in the value string. The syntax is as follows:

{=VariableName}

There are some predefined CodeBlocks:

{=Newline}: NewLine character;

{=Tab}: Tab;

{=WhiteSpace}: White Space

{=DateTime}: Current DateTime; The format can be provided by the IParameterProvider through the property 'dateTimeFormat'

{=DoubleQuote}: Double Quote

{=SingleQuote}: Single Quote

The value string format will be kept so you can choose whether use the predefined formatting CodeBlock in the string or just format the string in the configuration file.-->

  <emailer smtpServer="192.168.0.2" maxNumberOfRecipientsPerEmail="20"from="no-reply@netemailer.com" isBodyHtml="false" enableSSL="false"timeout="100000">

    <!-- Default setting will be overrite by specific setting belows if it's not empty string in the specific section -->

    <!--Maximum number of recipients in each recipient list(to, cc, bcc), Emailer will split them into several emails if the list length exceed this number -->

    <!--Timeout value is in milliseconds-->

    <!--priority value can be "High","Low" or "Normal"-->

    <!--{=VariableName} can be used in any value string except for dateTimeFormat-->

    <!--if the smtpServer authentication required SSL,set enableSSL="true"-->

    <emailname="Email Health Test">

      <addname="to" value="" />

      <addname="cc" value="yourname@yourorg.com" />

      <addname="bcc" value="" />

      <addname="priority" value="Normal" />

      <addname="subject" value="{=ApplicationAcronym} Email Health Test" />

      <addname="isBodyHtml" value="true" />

      <!--To send Html email, set 'isBodyHtml' to true; use <![CDATA[]]> to wrap the html-->

      <addname="body">

        <![CDATA[

      <html>

        <title>Html Email Sample</title>

        <body>This message was sent <b>{=DateTime}</b> from {=ApplicationAcronym} system.<br>copyright?/span>2006 ZSU</body>

      </html>]]>

      </add>

    </email>

    <emailname="User Account Request">

      <addname="to" value="yourname@yourorg.com" />

      <addname="from" value="no-reply@yourorg.com" />

      <addname="cc" value="" />

      <addname="bcc" value="" />

      <addname="priority" value="Normal" />

      <addname="subject" value="{=ApplicationAcronym} User Account Request" />

      <addname="body" value="A {=ApplicationAcronym} user account request was submitted {=DateTime} for:

              

        User Name: {=UserName}

        Organization: {=Organization}

       

Please log into {=ApplicationAcronym} and approve or deny the request for this user." />

      <!--Optional. It's used for formating the {=DateTime} CodeBlock. The default setting is "MMMM d, yyyy \"at\" HH:mm ET". Refer to DateTime Format for more detail. -->

      <addname="dateTimeFormat" value="MMMM d, yyyy 'at' HH:mm ET" />

    </email>

  </emailer>

</configuration>

 

4.     Build the message and send it out:

      EmailMessage oMessage = Emailer.BuildMessage(?NetEmailer.config?, ?User Account Request?, new ParamProvider());

      oMessage.Send();

ParamProvider is a class that implements the IParameterProvider interface. IParameterProvider only defines one funtion signature:

string GetProperty(string sname);

It’s purpose is to provide dynamic information to the CodeBlock({=variablename} defined in the configuration file.

The latest version is 1.2 and you can download the sample code with the NetEmailer.dll here.

Contact the author here

 

Copyright@2006 zsu

 

If you like NetEmailer, please consider supporting this project and make a donation. Thank you for your support!