use of com.serotonin.web.mail.EmailSender in project ma-core-public by infiniteautomation.
the class EmailWorkItem method execute.
@Override
public void execute() {
Exception failedEx = null;
boolean success = true;
try {
if (fromAddress == null) {
String addr = SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_FROM_ADDRESS);
String pretty = SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_FROM_NAME);
fromAddress = new InternetAddress(addr, pretty);
}
EmailSender emailSender = new EmailSender(SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_SMTP_HOST), SystemSettingsDao.getIntValue(SystemSettingsDao.EMAIL_SMTP_PORT), SystemSettingsDao.getBooleanValue(SystemSettingsDao.EMAIL_AUTHORIZATION), SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_SMTP_USERNAME), SystemSettingsDao.getValue(SystemSettingsDao.EMAIL_SMTP_PASSWORD), SystemSettingsDao.getBooleanValue(SystemSettingsDao.EMAIL_TLS));
emailSender.send(fromAddress, toAddresses, subject, content);
} catch (Exception e) {
LOG.warn("Error sending email", e);
failedEx = e;
success = false;
String to = "";
for (InternetAddress addr : toAddresses) {
if (to.length() > 0)
to += ", ";
to += addr.getAddress();
}
SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_EMAIL_SEND_FAILURE), Common.timer.currentTimeMillis(), false, new TranslatableMessage("event.email.failure", subject, to, e.getMessage()));
} finally {
if (postSendExecution != null) {
for (PostEmailRunnable runnable : postSendExecution) runnable.emailFinished(success, failedEx);
}
}
}
Aggregations