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);
}
}
}
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.");
}
}
Aggregations