Search in sources :

Example 36 with MailException

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());
    }
}
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 37 with MailException

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());
    }
}
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 38 with MailException

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

Example 39 with MailException

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);
        }
    }
}
Also used : MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) DataHandler(javax.activation.DataHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MailException(org.springframework.mail.MailException)

Example 40 with MailException

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

Aggregations

MailException (org.springframework.mail.MailException)47 MimeMessage (javax.mail.internet.MimeMessage)18 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)17 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)15 MessagingException (javax.mail.MessagingException)10 Date (java.util.Date)8 Properties (java.util.Properties)3 InternetAddress (javax.mail.internet.InternetAddress)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 AuthenticationFailedException (jakarta.mail.AuthenticationFailedException)2 MessagingException (jakarta.mail.MessagingException)2 NoSuchProviderException (jakarta.mail.NoSuchProviderException)2 MimeMessage (jakarta.mail.internet.MimeMessage)2 PrintWriter (java.io.PrintWriter)2 URI (java.net.URI)2 Matcher (java.util.regex.Matcher)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 MolgenisDataException (org.molgenis.data.MolgenisDataException)2