This project is read-only.

Email settings config example

These keys have to be accessible by the DLL. Most likley in the base project that will be compiled.

    <add key="EmailTestMode" value="false" />
    <add key="EmailTestTo" value="" />

    <add key="EmailSMTP" value="" />
    <add key="EmailDefaultFrom" value="" />
    <add key="EmailBCC" value=";;" />

Generating Key Value Pairs for template merging

List<KeyValuePair<string, string>> variables = new List<KeyValuePair<string, string>>();
 variables.Add(new KeyValuePair<string, string>("$NAME$", _name));
 variables.Add(new KeyValuePair<string, string>("$EMAIL$", _email));
 variables.Add(new KeyValuePair<string, string>("$DATE$", string.Format("{0:dddd dd MMM yyyy hh:mm tt}",  Time.GetGMTNow())));

Then you call MergeTemplateAndVariables method, pass in the full path of the HTML file and the KeyPair list. This will take the HTML file and replace all the text placeholders $PLACEHOLDER$ and return HTML

Production example

public class Email
  public static bool SendReset(string email){
    string passwordResetToken = WebSecurity.GeneratePasswordResetToken(email, 60);

    //generate content from template email

    List<KeyValuePair<string, string>> emlvar = new List<KeyValuePair<string, string>>();
    variables.Add(new KeyValuePair<string, string>("$RESETTOKEN$", passwordResetToken));
    string body = KulaTools.Email.MergeTemplateAndVariables(
         + "Emails\\PasswordReset.html", emlvar);

    var result = KulaTools.Email.Send(new KulaTools.Models.Email()
      Subject = "Password reset request",
      From = "", //will use the webconfig - EmailDefaultFrom
      Recipient = email,
      Body = body,
      IsHtml = true

    return result.HasErrors;

Last edited Jun 21, 2013 at 8:56 AM by ppumkin, version 8


No comments yet.