This project is read-only.

Usage From Code

The main Mail Toolkit interface is the static class Altairis.MailToolkit.Mailer.

Using the Mailer class

This class has two static methods (each with numerous overloads):
  • SendTemplatedMessage - sends message to single recpients
  • SendTemplatedMessages - sends message to multiple recipients

SendTemplatedMessage method parameters

The SendTemplatedMessage has several overloads where various combination of parameters is used.
  • culture - culture used for localized resources (message texts). If this parameter is set to null or if some overload without this parameter is used, current UiCulture is used. Standard fallback rules for unknown cultures are used.
  • replyTo - the address used for Reply-To header (see E-mail basics for details). If this parameter is set to null or if some overload without this parameter is used, value specified in configuration is used. If reply address is not specified in configuration, Reply-To header is not added and replies are directed to From address.
  • recipient - recipient of the messsage. May be either string containing e-mail address literal or instance of System.Net.Mail.MailAddress class, where display name may be specified along with the address.
  • templateName - name of template used for generating mail. See Preparing resource files for details about template creation.
  • args - arguments used by string.Format method for placeholder expansion.

SendTemplatedMessages method parameters

The same parameters are used as for SendTemplatedMessage above. Only instead of recipient there is recipients parameter of type IEnumerable<string> or IEnumerable<System.Net.Mail.MailAddress>.

When sending message to multiple recipients, single copy is sent for each recipient. That means that recipient can see only his own name in the To header and has no knowledge about other recipients

Examples

Send simple templated message using current culture setting and default reply address:
Altairis.MailToolkit.Mailer.SendTemplatedMessage(
    "recipient@example.com",                   // recipient e-mail address
    "MyTemplate",                              // template name
    "Placeholder value 0",                     // {0}
    "Placeholder value 1");                    // {1}

Send templated message while specifying custom reply address:
Altairis.MailToolkit.Mailer.SendTemplatedMessage(
    new MailAddress("reply-to@example.com"),   // reply-to e-mail address
    new MailAddress("recipient@example.com"),  // recipient e-mail address
    "MyTemplate",                              // template name
    "Placeholder value 0",                     // {0}
    "Placeholder value 1");                    // {1}

Send message in specific language (Czech, in the example):
Altairis.MailToolkit.Mailer.SendTemplatedMessage(
    new CultureInfo("cs-CZ"),                  // localization culture
    "recipient@example.com",                   // recipient e-mail address
    "MyTemplate",                              // template name
    "Placeholder value 0",                     // {0}
    "Placeholder value 1");                    // {1}

Last edited Jun 3, 2013 at 2:51 PM by altair, version 2

Comments

No comments yet.