use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.
the class OpenClinicaMailSender method sendEmail.
public void sendEmail(String to, String from, String subject, String body, Boolean htmlEmail) throws OpenClinicaSystemException {
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, htmlEmail);
helper.setFrom(from);
helper.setTo(processMultipleImailAddresses(to.trim()));
helper.setSubject(subject);
helper.setText(body, true);
mailSender.send(mimeMessage);
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
logger.debug("Email could not be sent on {} due to: {}", new Date(), me.toString());
throw new OpenClinicaSystemException(me.getMessage());
} catch (MessagingException e) {
logger.debug("Email could not be sent on {} due to: {}", new Date(), e.toString());
throw new OpenClinicaSystemException(e.getMessage());
}
}
use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.
the class EmailActionProcessor method sendEmail.
private void sendEmail(RuleActionBean ruleAction, UserAccountBean ub, String body, String subject) throws OpenClinicaSystemException {
logger.info("Sending email...");
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
helper.setFrom(EmailEngine.getAdminEmail());
helper.setTo(processMultipleImailAddresses(((EmailActionBean) ruleAction).getTo().trim()));
helper.setSubject(subject);
helper.setText(body);
mailSender.send(mimeMessage);
System.out.println("Sending Email thru Email Action");
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
logger.error("Email could not be sent");
throw new OpenClinicaSystemException(me.getMessage());
} catch (MessagingException me) {
logger.error("Email could not be sent");
throw new OpenClinicaSystemException(me.getMessage());
}
}
use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.
the class SystemController method sendEmail.
public String sendEmail(JavaMailSenderImpl mailSender, String emailSubject, String message) throws OpenClinicaSystemException {
logger.info("Sending email...");
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
helper.setFrom(EmailEngine.getAdminEmail());
helper.setTo("oc123@openclinica.com");
helper.setSubject(emailSubject);
helper.setText(message);
mailSender.send(mimeMessage);
return "ACTIVE";
} catch (MailException me) {
return "INACTIVE";
} catch (MessagingException me) {
return "INACTIVE";
}
}
use of org.springframework.mail.MailException in project BroadleafCommerce by BroadleafCommerce.
the class LoggingMailSender method send.
@Override
public void send(MimeMessagePreparator[] mimeMessagePreparators) throws MailException {
for (MimeMessagePreparator preparator : mimeMessagePreparators) {
try {
MimeMessage mimeMessage = createMimeMessage();
preparator.prepare(mimeMessage);
LOG.info("\"Sending\" email: ");
if (mimeMessage.getContent() instanceof MimeMultipart) {
MimeMultipart msg = (MimeMultipart) mimeMessage.getContent();
DataHandler dh = msg.getBodyPart(0).getDataHandler();
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
dh.writeTo(baos);
} catch (Exception e) {
// Do nothing
} finally {
try {
baos.close();
} catch (Exception e) {
LOG.error("Couldn't close byte array output stream");
}
}
} else {
LOG.info(mimeMessage.getContent());
}
} catch (Exception e) {
LOG.error("Could not create message", e);
}
}
}
use of org.springframework.mail.MailException in project perun by CESNET.
the class MailManagerImpl method appErrorVoAdmin.
private void appErrorVoAdmin(Application app, ApplicationMail mail, List<ApplicationFormItemData> data, String reason, List<Exception> exceptions) throws MessagingException {
MimeMessage message = getAdminMessage(app, mail, data, reason, exceptions);
// send a message to all VO or Group admins
List<String> toEmail = getToMailAddresses(app);
for (String email : toEmail) {
setRecipient(message, email);
try {
mailSender.send(message);
log.info("[MAIL MANAGER] Sending mail: APP_ERROR_VO_ADMIN to: {} / appID: {} / {} / {}", message.getAllRecipients(), app.getId(), app.getVo(), app.getGroup());
} catch (MailException ex) {
log.error("[MAIL MANAGER] Sending mail: APP_ERROR_VO_ADMIN failed because of exception.", ex);
}
}
}
Aggregations