Search in sources :

Example 1 with MailConnectException

use of com.sun.mail.util.MailConnectException in project Payara by payara.

the class EmailNotificationRunnable method run.

@Override
public void run() {
    while (queue.size() > 0) {
        try {
            EmailMessage emailMessage = queue.getMessage();
            Message message = new MimeMessage(session);
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(executionOptions.getTo()));
            message.setSubject(emailMessage.getSubject());
            message.setText(emailMessage.getMessage());
            Transport.send(message);
            logger.log(Level.FINE, "Email successfully sent");
        } catch (IllegalArgumentException e) {
            logger.log(Level.SEVERE, "mail configuration properties are not provided carefully.", e);
        } catch (AuthenticationFailedException e) {
            logger.log(Level.SEVERE, "Username and Password not accepted.", e);
        } catch (MailConnectException e) {
            if (e.getCause() instanceof UnknownHostException) {
                logger.log(Level.SEVERE, "Cannot connect to mail server with given host address", e);
            } else {
                logger.log(Level.SEVERE, "Cannot connect to mail server", e);
            }
        } catch (MessagingException e) {
            logger.log(Level.SEVERE, "Error occurred while trying to send mail.", e);
        }
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) UnknownHostException(java.net.UnknownHostException) MimeMessage(javax.mail.internet.MimeMessage) MailConnectException(com.sun.mail.util.MailConnectException)

Example 2 with MailConnectException

use of com.sun.mail.util.MailConnectException in project ArachneCentralAPI by OHDSI.

the class ArachneMailSender method send.

public void send(ArachneMailMessage mailMessage) {
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper;
    try {
        helper = new MimeMessageHelper(message, true);
        helper.setSubject(mailMessage.getSubject());
        helper.setFrom(from, mailMessage.getFromPersonal());
        helper.setTo(mailMessage.getUser().getEmail());
        helper.setText(buildContent(mailMessage.getTemplate(), mailMessage.getParameters()), true);
        mailSender.send(message);
    } catch (MailConnectException e) {
        LOG.error(e.getMessage(), e);
        throw new MailSendException(e.getMessage());
    } catch (MessagingException | UnsupportedEncodingException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (MailSendException e) {
        LOG.error(e.getMessage(), e);
        throw new MailSendException("Failed to send e-mail. Please, contact to the administrator.");
    }
}
Also used : MailSendException(org.springframework.mail.MailSendException) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MailConnectException(com.sun.mail.util.MailConnectException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Aggregations

MailConnectException (com.sun.mail.util.MailConnectException)2 MimeMessage (javax.mail.internet.MimeMessage)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 UnknownHostException (java.net.UnknownHostException)1 MessagingException (javax.mail.MessagingException)1 MailSendException (org.springframework.mail.MailSendException)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1