Search in sources :

Example 6 with MimeMessageHelper

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);
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MimeMessage(javax.mail.internet.MimeMessage) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Example 7 with MimeMessageHelper

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());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Date(java.util.Date)

Example 8 with MimeMessageHelper

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");
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) Date(java.util.Date)

Example 9 with MimeMessageHelper

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());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Date(java.util.Date)

Example 10 with MimeMessageHelper

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());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Date(java.util.Date)

Aggregations

MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)18 MimeMessage (javax.mail.internet.MimeMessage)17 MailException (org.springframework.mail.MailException)9 MessagingException (javax.mail.MessagingException)8 Date (java.util.Date)7 Properties (java.util.Properties)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)3 SendmailMessage (org.opennms.netmgt.config.javamail.SendmailMessage)2 MimeMessagePreparator (org.springframework.mail.javamail.MimeMessagePreparator)2 Async (org.springframework.scheduling.annotation.Async)2 File (java.io.File)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Stream (java.util.stream.Stream)1 InternetAddress (javax.mail.internet.InternetAddress)1 JavaMailerException (org.opennms.javamail.JavaMailerException)1 JavaSendMailer (org.opennms.javamail.JavaSendMailer)1