You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 12
Next »
Introduction
This article provides information on how to configure different mail parameters in JobSchedulerManagedMailJob.
Job Parameters
The parameters for this job may be set as job or order parameters
Parameter | Description | Required |
---|
to | mail recipient(s) | Yes |
cc | cc recipient(s) | no |
bcc | bcc recipient(s) | no |
from | mail sender | no |
from_name | name of the sender | no |
reply_to | reply address | no |
subject | Mail Subject | no |
host | mail server host | no |
port | mail server port | no |
smtp_user | smtp username | no |
smtp_password | smtp user password | no |
queue_directory | Mail queue directory. Mails which cannot be transferred will be put here. The JobScheduler will later retry to send these mails. | no |
body | Mail body | no |
content_type | content_type of the mail (text/plain, text/html...) | no |
encoding | encoding of the mail (7bit, Quoted-Printable, Base64) | no |
charset | charset of the mail | no |
attachment_content_type | content_type of attachments (application/octet-stream, application/pdf...) | no |
attachment_encoding | encoding of attachments (7bit, Quoted-Printable, Base64) | no |
attachment_charset | charset of attachments | no |
attachment | Filename and path of the attachment(s) (multiple attachments separated by ";") | no |
A Simple JITL Send Email Example Examples
Following example shows a basic job configuration of JobSchedulerManagedMailJob. It is been configured to send email to a fix email Id along with fix email body and subject line.
See example 01_SendEmail.job_chain.xml in the downloadable example.
<job title="Send eMails" stop_on_error="no">
<settings >
<log_level ><![CDATA[debug9]]></log_level>
</settings>
<description >
<include file="jobs/JobSchedulerManagedMailJob.xml"/>
</description>
<params >
<param name="to" value="jobscheduler-admin-group@sos-berlin.com"/>
<param name="from" value="gollum.sos@sos-berlin.com"/>
<param name="from_name" value="JobScheduler Gollum"/>
<param name="content_type" value="text/html"/>
<param name="body" value="This is a test email."/>
<param name="reply_to" value="jobscheduler-admin-group@sos-berlin.com"/>
<param name="subject" value="Test Email"/>
</params>
<script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedMailJob"/>
<run_time />
</job>
Dynamically configure email subject and body text
As any other JITL job JobSchedulerManagedMailJob's parameters can also be configured dynamically using pre processor monitor. In following example we will dynamically set the value for parameters subject and body.
The outgoing mails body and subject will be dynamically configured depending upon week day.
See example 02_ProcessingDayEmail.job_chain.xml in the downloadable example.
<?xml version="1.0" encoding="ISO-8859-1"?>
<job title="Send eMails" stop_on_error="no" order="yes" name="day_of_processing_email">
<description >
<include file="jobs/JobSchedulerManagedMailJob.xml"/>
</description>
<params >
<param name="to" value="jobscheduler-admin-group@sos-berlin.com"/>
<param name="from" value="gollum.sos@sos-berlin.com"/>
<param name="from_name" value="JobScheduler Gollum"/>
<param name="content_type" value="text/html"/>
</params>
<script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedMailJob"/>
<monitor name="PreConfigureEmail" ordering="0">
<script language="javax.script:ecmascript">
<![CDATA[
function spooler_process_before() {
try {
var htmlHeader="<html><head></head><body>";
var htmlFooter="</body></html>\n\n";
var messageBody="";
var messageSubject="";
var today = new Date();
var todayWeekDay = today.getDay();
var weekdayName = [ "Sunday" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" ];
if ( todayWeekDay <= 1 && todayWeekDay >= 5 ){
spooler_log.info( ".. Today's Weekday: " + weekdayName[ todayWeekDay ] );
messageSubject="Weekend Job Processing day of the week : " + weekdayName[ todayWeekDay ];
messageBody = htmlHeader + messageSubject + htmlFooter;
} else {
spooler_log.info( ".. Today's Weekday: " + weekdayName[ todayWeekDay ] );
messageSubject=" Weekday Job Processing day of the week : " + weekdayName[ todayWeekDay ];
messageBody = htmlHeader + messageSubject + htmlFooter;
}
spooler_log.info( ".. body: " + messageBody );
spooler_log.info( ".. messageSubject: " + messageSubject );
spooler_task.order().params().set_value("body",messageBody);
spooler_task.order().params().set_value("subject",messageSubject);
return true;
} catch (e) {
spooler_log.warn("error occurred : " + String(e));
return false;
}
}
]]>
</script>
</monitor>
<run_time />
</job>
Dynamically configure email subject, body and attachment file name
A common use case for configuring subject, body and file attachment is when job chain is triggered using file order source and file should be attached with outgoing email or file name need be specified in the mail's body text.
In the following example we will take a complex example of sending email with attachments, also following example shows how to crate custom mail message body and on run time replace information such as file name.
In the following example job is getting file name from JobScheduler's order parameter scheduler_file_path.
See example 03_SendInvoiceEmail.job_chain.xml in the downloadable example.
<job title="Send eMails" stop_on_error="no" order="yes" name="send_email_with_attachment">
<description >
<include file="jobs/JobSchedulerManagedMailJob.xml"/>
</description>
<params >
<param name="to" value="jobscheduler-admin-group@sos-berlin.com"/>
<param name="from" value="gollum.sos@sos-berlin.com"/>
<param name="from_name" value="JobScheduler Gollum"/>
<param name="content_type" value="text/html"/>
</params>
<script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedMailJob"/>
<monitor name="PreConfigureEmail" ordering="0">
<script language="javax.script:ecmascript">
<![CDATA[
function spooler_process_before() {
try {
// get filename from the scheduler_file_path variables
var filePath = "" + String(orderParameters.value("scheduler_file_path"));
spooler_log.info( " scheduler_file_path : " + filePath );
var fileParts = filePath.split("/");
var fileName = fileParts[fileParts.length-1];
spooler_log.info( "fileName : " + fileName );
var htmlHeader="<html><head></head><body>";
var htmlFooter="</body></html>\n\n";
// define a message body template with PROCESS_FILE_OUT anchor which will be replaced later with file name which has triggerd the job chain.
var messageBodyTemplate="Dear Customer, <br>Please find the invoice file attached herewith. <br> FileName = PROCCESSED_FILE_OUT <br> Best regards <br> SOS GmbH <br> <br> <br> ** This is an automaticlly generated E-mail, Please do not reply. ** <br> ---------------------------------------------------------------------------------------------------- ";
// set email's subject
messageSubject="[ Invoice ] " + fileName;
// set email's body and replace anchor text with file name
messageBody = htmlHeader + messageBodyTemplate.replace("PROCCESSED_FILE_OUT",fileName) + htmlFooter;
spooler_log.info( ".. body: " + messageBody );
spooler_log.info( ".. messageSubject: " + messageSubject );
spooler_task.order().params().set_value("body",messageBody);
spooler_task.order().params().set_value("subject",messageSubject);
spooler_task.order().params().set_value("attachment",filePath);
return true;
} catch (e) {
spooler_log.warn("error occurred : " + String(e));
return false;
}
}
]]>
</script>
</monitor>
<run_time />
</job>
See also