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 NotificationActionProcessor method sendEmail.
private void sendEmail(RuleActionBean ruleAction, ParticipantDTO pDTO) throws OpenClinicaSystemException {
logger.info("Sending email...");
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
helper.setFrom(EmailEngine.getAdminEmail());
helper.setTo(pDTO.getEmailAccount());
helper.setSubject(pDTO.getEmailSubject());
helper.setText(pDTO.getMessage());
mailSender.send(mimeMessage);
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 OpenClinica by OpenClinica.
the class SecureController method sendEmail.
public Boolean sendEmail(String to, String from, String subject, String body, Boolean htmlEmail, String successMessage, String failMessage, Boolean sendMessage) throws Exception {
Boolean messageSent = true;
try {
JavaMailSenderImpl mailSender = (JavaMailSenderImpl) SpringServletAccess.getApplicationContext(context).getBean("mailSender");
//@pgawade 09-Feb-2012 #issue 13201 - setting the "mail.smtp.localhost" property to localhost when java API is not able to
//retrieve the host name
Properties javaMailProperties = mailSender.getJavaMailProperties();
if (null != javaMailProperties) {
if (javaMailProperties.get("mail.smtp.localhost") == null || ((String) javaMailProperties.get("mail.smtp.localhost")).equalsIgnoreCase("")) {
javaMailProperties.put("mail.smtp.localhost", "localhost");
}
}
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);
if (successMessage != null && sendMessage) {
addPageMessage(successMessage);
}
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
me.printStackTrace();
if (failMessage != null && sendMessage) {
addPageMessage(failMessage);
}
logger.debug("Email could not be sent on {} due to: {}", new Date(), me.toString());
messageSent = false;
}
return messageSent;
}
use of org.springframework.mail.MailException in project bamboobsc by billchen198318.
the class MailClientUtils method send.
public static void send(String from, String to, String[] cc, String[] bcc, String[] fileNames, File[] files, String subject, String text) throws MailException, Exception {
if (mailSender == null) {
throw new Exception("null mailSender!");
}
if (StringUtils.isBlank(from) || StringUtils.isBlank(to)) {
throw new Exception("from and to is required!");
}
if (fileNames != null && files != null) {
if (fileNames.length != files.length) {
throw new Exception("File parameter error!");
}
}
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, Constants.BASE_ENCODING);
helper.setFrom(from);
helper.setTo(to.endsWith(";") ? to.substring(0, to.length() - 1) : to);
helper.setSubject(subject);
helper.setText(text, true);
if (null != cc && cc.length > 0) {
helper.setCc(cc);
}
if (null != bcc && bcc.length > 0) {
helper.setBcc(bcc);
}
for (int i = 0; fileNames != null && i < fileNames.length; i++) {
helper.addAttachment(fileNames[i], files[i]);
}
mailSender.send(message);
}
Aggregations