use of org.springframework.mail.javamail.MimeMessageHelper in project disconf by knightliao.
the class MailBean method sendHtmlMail.
/**
* 发送html邮件
*
* @throws MessagingException
* @throws AddressException
*/
public void sendHtmlMail(String from, String[] to, String title, String text) throws AddressException, MessagingException {
long start = System.currentTimeMillis();
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, "GBK");
InternetAddress[] toArray = new InternetAddress[to.length];
for (int i = 0; i < to.length; i++) {
toArray[i] = new InternetAddress(to[i]);
}
messageHelper.setFrom(new InternetAddress(from));
messageHelper.setTo(toArray);
messageHelper.setSubject(title);
messageHelper.setText(text, true);
mimeMessage = messageHelper.getMimeMessage();
mailSender.send(mimeMessage);
long end = System.currentTimeMillis();
LOG.info("send mail start:" + start + " end :" + end);
}
use of org.springframework.mail.javamail.MimeMessageHelper 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.javamail.MimeMessageHelper in project OpenClinica by OpenClinica.
the class RandomizationRegistrar method sendEmail.
public void sendEmail(JavaMailSenderImpl mailSender, UserAccountBean user, 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(user.getEmail());
helper.setSubject(emailSubject);
helper.setText(message);
mailSender.send(mimeMessage);
logger.debug("Email sent successfully on {}", new Date());
} catch (MailException me) {
logger.error("Email could not be sent");
} catch (MessagingException me) {
logger.error("Email could not be sent");
}
}
use of org.springframework.mail.javamail.MimeMessageHelper 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.javamail.MimeMessageHelper 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());
}
}
Aggregations