Using the EmailTasklet
(full name : Summer.Batch.Extra.EmailSupport.EmailTasklet
), you can send email using the SMTP protocol. This tasklet relies on the System.Net.Mail.SmtpClient
to perform
the mail sending 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 : the from email address for sending mails;
Subject : the subject of the mail to be sent;
Body : resource path to the mail body content;
At least a recipient must be specified: the recipients are stored in three separate lists:
To : list of direct recipients addresses for the mail;
Cc : list of copy recipients addresses for the mail;
Bcc : list of hidden copy recipients addresses for the mail;
At least one of these lists must be non-empty.
Optional properties (need to be set at initialization time, but a default value is provided if needed):
Username : if the smtp server requires a user name, this property should contain it; No default value;
Password : if the smtp server requires a password for the username, this property should contain it; No defaut 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 : a positive or equal to zero 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
and here 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();
…