Skip to content

Email sending support

Using EmailTasklet (full name : Summer.Batch.Extra.EmailSupport.EmailTasklet) you can send email by SMTP protocol. This tasklet relies on System.Net.Mail.SmtpClient to perform this operations.

The following properties are mandatory (need to be set at initialization time):

  • Host : name or I.P. address of the SMTP server used for sending mails;

  • From : from email address for sending mails;

  • Subject : subject of the mail to be sent;

  • Body : resource path to mail body;

  • At least one recipient must be specified: recipients are stored in three separate lists:

    • To : list of direct recipients addresses for mail;

    • Cc : list of copy recipients addresses for mail;

    • Bcc : list of hidden copy recipients addresses for mail;

    At least one of these lists must be non-empty.

Optional properties (Default value is provided, however can set at initialization time):

  • Username : to be provided if the SMTP server requires a user name; No default value;

  • Password : to be provided if the SMTP server requires a password for the username; No default value;

  • InputEncoding : input encoding of the mail body (read); defaults to the platform default encoding;

  • Encoding : encoding of the mail to be sent (write); defaults to the platform default encoding;

  • Port : SMTP server port; defaults to 25;

  • LineLength : zero or a positive integer to indicate the maximum line length used for reading the mail body; if 0, the whole body will be read in a single pass (default option); otherwise, the body will be read line by line of the specified LineLength size.

Configuring the EmailTasklet in the job XML file:

Example 7.12. EmailTasklet usage in the job XML file

<step id="EmailStep">
    <batchlet ref="EmailBatchlet" />
</step>
and below is a sample Unity configuration :

Example 7.13. EmailTasklet Unity configuration


/// <summary>
/// Registers the artifacts required for step EmailStep.
/// </summary>
/// <param name="container">the unity container to use for registrations</param>
private void RegisterEmailStep(IUnityContainer container)
{
            container.StepScopeRegistration<ITasklet, EmailTasklet>("EmailBatchlet")
                .Property("Host").Value("mysmptserver")
                .Property("Body").Resource("#{settings['EmailBatchlet.BODY']}")
                .Property("From").Value("anonymous@mycompany.com")
                .Property("Subject").Value("test email from batch system")
                .Property("To").LateBinding<string[]>("t.masson@bluage.com")
                .Property("Encoding").Value(Encoding.GetEncoding("UTF-8"))
                .Property("InputEncoding").Value(Encoding.GetEncoding("IBM01047"))
                .Property("LineLength").Value(80)
                .Register();