Example usage for javax.mail MessagingException getMessage

List of usage examples for javax.mail MessagingException getMessage

Introduction

In this page you can find the example usage for javax.mail MessagingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.nuxeo.ecm.platform.notification.async.AdvancedNotificationEventListener.java

public void sendNotification(Event event, DocumentEventContext ctx) throws ClientException {

    String eventId = event.getName();
    log.debug("Received a message for notification sender with eventId : " + eventId);

    Map<String, Serializable> eventInfo = ctx.getProperties();
    String userDest = (String) eventInfo.get(NotificationConstants.DESTINATION_KEY);
    NotificationImpl notif = (NotificationImpl) eventInfo.get(NotificationConstants.NOTIFICATION_KEY);

    // send email
    NuxeoPrincipal recepient = NotificationServiceHelper.getUsersService().getPrincipal(userDest);
    if (recepient == null) {
        log.error("Couldn't find user: " + userDest + " to send her a mail.");
        return;// www.j  ava  2  s  . co m
    }
    // XXX hack, principals have only one model
    DataModel model = recepient.getModel().getDataModels().values().iterator().next();
    String email = (String) model.getData("email");
    if (email == null || "".equals(email)) {
        log.error("No email found for user: " + userDest);
        return;
    }

    String subjectTemplate = notif.getSubjectTemplate();

    String mailTemplate = null;
    // mail template can be dynamically computed from a MVEL expression
    if (notif.getTemplateExpr() != null) {
        mailTemplate = emailHelper.evaluateMvelExpresssion(notif.getTemplateExpr(), eventInfo);
    }
    // if there is no mailTemplate evaluated, use the defined one
    if (StringUtils.isEmpty(mailTemplate)) {
        mailTemplate = notif.getTemplate();
    }

    log.debug("email: " + email);
    log.debug("mail template: " + mailTemplate);
    log.debug("subject template: " + subjectTemplate);

    Map<String, Object> mail = new HashMap<String, Object>();
    mail.put("mail.to", email);

    String authorUsername = (String) eventInfo.get(NotificationConstants.AUTHOR_KEY);

    if (authorUsername != null) {
        NuxeoPrincipal author = NotificationServiceHelper.getUsersService().getPrincipal(authorUsername);
        mail.put(NotificationConstants.PRINCIPAL_AUTHOR_KEY, author);
    }

    mail.put(NotificationConstants.DOCUMENT_KEY, ctx.getSourceDocument());
    String subject = notif.getSubject() == null ? NotificationConstants.NOTIFICATION_KEY : notif.getSubject();
    subject = notificationService.getEMailSubjectPrefix() + subject;
    mail.put("subject", subject);
    mail.put("template", mailTemplate);
    mail.put("subjectTemplate", subjectTemplate);

    // Transferring all data from event to email
    for (String key : eventInfo.keySet()) {
        mail.put(key, eventInfo.get(key) == null ? "" : eventInfo.get(key));
        log.debug("Mail prop: " + key);
    }

    mail.put(NotificationConstants.EVENT_ID_KEY, eventId);

    try {
        emailHelper.sendmail(mail);
    } catch (MessagingException e) {
        log.warn("Failed to send notification email to '" + email + "': " + e.getClass().getName() + ": "
                + e.getMessage());
    } catch (Exception e) {
        throw new ClientException("Failed to send notification email ", e);
    }
}

From source file:fsi_admin.JSmtpConn.java

private boolean sendMsg(String HOST, String USERNAME, String PASSWORD, StringBuffer msj, Session session,
        MimeMessage mmsg, MimeMultipart multipart) {
    try {/*www  .j  av  a  2 s. co  m*/
        mmsg.setContent(multipart);
        // Create a transport.        
        Transport transport = session.getTransport();
        // Send the message.
        System.out.println(HOST + " " + USERNAME + " " + PASSWORD);
        transport.connect(HOST, USERNAME, PASSWORD);
        // Send the email.
        transport.sendMessage(mmsg, mmsg.getAllRecipients());
        transport.close();

        return true;
    } catch (MessagingException e) {
        e.printStackTrace();
        msj.append("Error de Mensajeria al enviar SMTP: " + e.getMessage());
        return false;
    } catch (Exception ex) {
        ex.printStackTrace();
        msj.append("Error general de mensaje al enviar SMTP: " + ex.getMessage());
        return false;
    }

}

From source file:de.teamgrit.grit.entities.Exercise.java

/**
 * Sends a warning mail to all Students without a submission. Only sends
 * mails 6 and 12 hours before deadline.
 * //from ww  w  . ja va 2 s . c o  m
 * @param studentsWithoutSubmissions
 *            List which contains all Students who did not submit anything
 *            yet.
 */
private void notifyStudentsWithoutSubmission(List<Student> studentsWithoutSubmissions) {
    long in12hours = System.currentTimeMillis() + (12 * 60 * 60 * 1000);
    long in6hours = System.currentTimeMillis() + (6 * 60 * 60 * 1000);
    long lowerBoundary = context.getDeadline().getTimeInMillis();
    long upperBoundary = context.getPeriod() + lowerBoundary;
    if (((in12hours >= lowerBoundary) && (in12hours < upperBoundary))
            || ((in6hours >= lowerBoundary) && (in6hours < upperBoundary))) {
        for (Student student : studentsWithoutSubmissions) {
            try {
                SendMailSSL.sendMail(GenerateMailObjectHelper.generateMailObjectNoSubmission(student, context));
            } catch (MessagingException e) {
                LOGGER.severe(
                        "Exception occured while trying to send mails " + "to students. " + e.getMessage());
            }
        }
    }
}

From source file:de.teamgrit.grit.entities.Exercise.java

/**
 * Checks if plausible flag or cleanCopile flag of submission is set or
 * not. Sends warning email to corresponding student if not. If set this
 * method does nothing./* www.ja v  a  2 s  . com*/
 * 
 * @param submissions
 *            List of submissions which contain all relevant data in order
 *            to send mails
 */
private void notifyStudentsWithCorruptedSubmission(List<Submission> submissions) {

    /*
     * for each submission we check if the flags isPlausible and
     * isCleanCompile are set
     */
    for (Submission sub : submissions) {

        /*
         * if the submission is not plausible we send a warning mail to the
         * student containing the message that files are missing
         */
        if (!sub.isPlausible()) {
            try {
                SendMailSSL.sendMail(GenerateMailObjectHelper.generateMailObjectMissingFiles(sub, context));
            } catch (MessagingException e) {
                LOGGER.severe(
                        "Exception occured while trying to send " + "mails to students. " + e.getMessage());
            }

        } else if (!sub.getCheckingResult().getCompilerOutput().isCleanCompile()) {
            /*
             * if the submission does not compile we send a warning mail to
             * the student containing all compiler errors,warnings and
             * infos
             */

            try {
                SendMailSSL.sendMail(GenerateMailObjectHelper.generateMailObjectDoesNotCompile(sub, context));
            } catch (MessagingException e) {
                LOGGER.severe(
                        "Exception occured while trying to send " + "mails to students. " + e.getMessage());
            }
        }
    }

}

From source file:com.cubusmail.server.services.MailboxService.java

public GWTMessage retrieveMessage(String folderId, long messageId, boolean loadImages) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();
    log.debug("retrieving message for " + messageId + " ...");

    try {//  w  w w  . j  ava  2  s  .  c om
        IMailFolder selectedFolder = mailbox.getCurrentFolder();
        Message msg = selectedFolder.getMessageById(messageId);

        MessageHandler handler = getMessageHandler(mailbox.getJavaMailSession(), (MimeMessage) msg);
        handler.readBodyContent(loadImages, MessageTextMode.DISPLAY);
        GWTMessage result = handler.getGWTMessage();

        return result;
    } catch (MessagingException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    }
}

From source file:com.cubusmail.server.services.MailboxService.java

public GWTMessage prepareReplyMessage(long messageId, boolean replyAll) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();
    log.debug("preparing reply message...");

    try {// w w w.ja  va 2s.  c o  m
        IMailFolder currentFolder = mailbox.getCurrentFolder();
        Message msg = currentFolder.getMessageById(messageId);

        MessageHandler replyMessageHandler = getMessageHandler(mailbox.getJavaMailSession());
        replyMessageHandler.createReplyMessage(msg, replyAll);

        SessionManager.get().setCurrentComposeMessage(replyMessageHandler);

        return replyMessageHandler.getGWTMessage();
    } catch (MessagingException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    }
}

From source file:com.cubusmail.server.services.MailboxService.java

public GWTMessage openDraftMessage(long messageId) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();
    log.debug("open message for " + messageId + " ...");

    try {/*from  w w  w  .ja v a  2  s  . c o m*/
        IMailFolder selectedFolder = mailbox.getCurrentFolder();
        Message msg = selectedFolder.getMessageById(messageId);

        MessageHandler readHandler = getMessageHandler(mailbox.getJavaMailSession(), (MimeMessage) msg);
        readHandler.readBodyContent(true, MessageTextMode.DRAFT);
        prepareNewMessage();

        GWTMessage result = readHandler.getGWTMessage();

        return result;
    } catch (MessagingException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    }
}

From source file:com.cubusmail.server.services.MailboxService.java

public GWTMessage prepareForwardMessage(long messageId) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();
    log.debug("preparing forward message...");

    try {/*from  www.ja va2 s.c om*/
        IMailFolder currentFolder = mailbox.getCurrentFolder();
        Message msg = currentFolder.getMessageById(messageId);

        MessageHandler forwardMessageHandler = getMessageHandler(mailbox.getJavaMailSession());
        forwardMessageHandler.createForwardMessage(msg);

        SessionManager.get().setCurrentComposeMessage(forwardMessageHandler);

        GWTMessage result = forwardMessageHandler.getGWTMessage();
        result.setAttachments(forwardMessageHandler.getGWTComposeAttachments());

        return result;
    } catch (MessagingException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new GWTMessageException(e.getMessage());
    }
}

From source file:com.hs.mail.mailet.RemoteDelivery.java

/**
 * Build error messages and make sure the error is permanent.
 * /*from www  .j a  v  a2s  . c o  m*/
 * @param message
 *            com.hs.mail.smtp.message.SmtpMessage
 * @param addresses
 *            addresses not delivered
 * @param ex
 *            javax.mail.MessagingException
 * @param permanent
 *            true if the exception is permanent error, false otherwise
 * @return Whether the message failed fully and can be deleted
 */
private boolean failMessage(SmtpMessage message, Address[] addresses, MessagingException ex,
        boolean permanent) {
    StringBuffer logBuffer = new StringBuffer(64).append((permanent) ? "Permanent" : "Temporary")
            .append(" exception delivering mail (").append(message.getName()).append("): ")
            .append(ex.getMessage().trim());
    logger.error(logBuffer.toString());
    if (!permanent) {
        int retries = message.getRetryCount();
        if (retries < maxRetries) {
            return false;
        }
    }
    if (message.isNotificationMessage()) {
        if (logger.isDebugEnabled())
            logger.debug("Null reverse-path: no bounce will be generated for " + message.getName());
        return true;
    }
    String errorMessage = buildErrorMessage(addresses, ex);
    message.appendErrorMessage(errorMessage);
    return true;
}

From source file:org.webcurator.core.notification.InTrayManagerImpl.java

private void send(String privilege, Task task) {
    List<UserDTO> userDTOs = userRoleDAO.getUserDTOsByPrivilege(privilege, task.getAgency().getOid());
    for (UserDTO user : userDTOs) {
        if (user.isTasksByEmail()) {
            //This user needs to be notified by email as well
            try {
                mailServer.sendHTML(convertTaskToMail(task, user.getEmail()));
            } catch (MessagingException e) {
                log.error("MailServer failure occurred during email of Task with message " + e.getMessage());
            }/*from  w  w  w .  j  av  a2 s .c om*/
        }
    }
}