er is now initialized with factory.ini defaults and settings
// from job/order parameters
// get mail object
SOSMail mail = mailer.getSosMail();
// change properties of the mail if needed:
mail.setBody("Hello World!");
//send mail
mail.send();
...
}
javascript version
There is also a javascript version of Scheduler Mailer in job/SchedulerMailer.js. This file can be included in javascript Jobs and used in the same way as in Java jobs. Example:
<job stop_on_error="yes" title="Javascript Mail" order="no"> <params> <param name="to" value="name@yourdomain.com"/> <param name="from_name" value="John Doe"/> <param name="body" value="This is the mail body"/> </params> <script language="javascript"> <include file="jobs/SchedulerMailer.js"/> <![CDATA[ function spooler_process(){ spooler_log.info("Creating mailer object"); var mailer = new schedulerMailer(); if (1==1){ mailer.sosMail.setSubject("OK"); } else{ mailer.sosMail.setSubject("NOK"); } mailer.sosMail.send(); return false; } ]]></script> <run_time> <period repeat="01:00"/> </run_time> </job>
Mail settings from the database
If the database contains the Job Scheduler SETTINGS table with a section for email settings, the mail defaults can also be read from there (instead of using the factory.ini defaults):
This only works for jobs which are subclassed from sos.scheduler.JobSchedulerJob.
If a job or order parameter
read_mail_settings
is set to "true", the mail defaults will be read from the SETTINGS table. (Afterwards, job and order parameters will be applied, and the SOSMail object can be changed).
@see sos.net.SOSMail
@author Andreas Liebert