} catch (Exception e) {
throw new Exception("error occurred checking parameters: " + e.getMessage());
}
try { // to process order
SOSMail sosMail;
Properties mailSection = null;
if (this.getConnectionSettings()!=null){
try{
mailSection = this.getConnectionSettings().getSection("email", "mail_server");
if (mailSection.size()<1) mailSection = null;
} catch(Exception e){
getLogger().debug6("No database settings found, using defaults from factory.ini");
}
}
if (mailSection!=null){
// use defaults from database settings
sosMail = new SOSMail(getConnectionSettings());
if (hostChanged) sosMail.setHost(host);
if (queueDirChanged) sosMail.setQueueDir(queueDir);
if (fromChanged) sosMail.setFrom(from);
}else {
// use defaults from Scheduler configuration
sosMail = new SOSMail(host);
sosMail.setQueueDir(queueDir);
sosMail.setFrom(from);
SOSSettings smtpSettings = new SOSProfileSettings(spooler.ini_path());
Properties smtpProperties = smtpSettings.getSection("smtp");
if (!smtpProperties.isEmpty()) {
if (smtpProperties.getProperty("mail.smtp.user") != null && smtpProperties.getProperty("mail.smtp.user").length() > 0) {
sosMail.setUser(smtpProperties.getProperty("mail.smtp.user"));
}
if (smtpProperties.getProperty("mail.smtp.password") != null && smtpProperties.getProperty("mail.smtp.password").length() > 0) {
sosMail.setPassword(smtpProperties.getProperty("mail.smtp.password"));
}
}
}
if (portChanged) sosMail.setPort(Integer.toString(port));
if (smtpUser.length()>0) sosMail.setUser(smtpUser);
if (smtpPass.length()>0) sosMail.setPassword(smtpPass);
// set values only if these are set by params, else use defaults from SOSMail
if (contentType.length()>0) sosMail.setContentType(contentType);
if (encoding.length()>0) sosMail.setEncoding(encoding);
if (attachmentCharset.length()>0) sosMail.setAttachmentCharset(attachmentCharset);
if (attachmentEncoding.length()>0)sosMail.setAttachmentEncoding(attachmentEncoding);
if (attachmentContentType.length()>0) sosMail.setAttachmentContentType(attachmentContentType);
if (fromName.length()>0) sosMail.setFromName(fromName);
String recipientsTo[] = to.split(";|,");
for(int i=0; i<recipientsTo.length; i++) {
if (i==0) sosMail.setReplyTo(recipientsTo[i].trim());
sosMail.addRecipient(recipientsTo[i].trim());
}
if (replyTo.length()>0) sosMail.setReplyTo(replyTo);
sosMail.addCC(cc);
sosMail.addBCC(bcc);
sosMail.setSubject(subject);
sosMail.setBody(body);
for(int i=0; i<attachments.length; i++) {
File attachmentFile = new File(attachments[i]);
SOSMailAttachment attachment = new SOSMailAttachment(sosMail, attachmentFile);
attachment.setCharset(sosMail.getAttachmentCharset());
attachment.setEncoding(sosMail.getAttachmentEncoding());
attachment.setContentType(sosMail.getAttachmentContentType());
sosMail.addAttachment(attachment);
}
sosMail.setSOSLogger(this.getLogger());
this.getLogger().info("sending mail: \n" + sosMail.dumpMessageAsString());
if (!sosMail.send()){
this.getLogger().warn("mail server is unavailable, mail for recipient [" + to + "] is queued in local directory [" + sosMail.getQueueDir() + "]:" + sosMail.getLastError());
}
if ( cleanupAttachment ) {
for(int i=0; i<attachments.length; i++) {
File attachmentFile = new File(attachments[i]);
if ( attachmentFile.exists() && attachmentFile.canWrite() ) {
SOSFile.deleteFile( attachmentFile );
}
}
}
sosMail.clearRecipients();
} catch (Exception e) {
throw new Exception(e.getMessage());
}