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:com.cubusmail.gwtui.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  a  va  2 s  .c  o  m*/
        IMailFolder selectedFolder = mailbox.getCurrentFolder();
        Message msg = selectedFolder.getMessageById(messageId);

        MessageHandler handler = MessageHandler.getInstance(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.gwtui.server.services.MailboxService.java

public void deleteMessages(long[] messageIds) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();

    if (messageIds != null && messageIds.length > 0) {
        log.debug("delete " + messageIds.length + " messages...");

        try {//from  w w  w.j a v  a2  s. co m
            if (mailbox.getCurrentFolder().isTrash() || mailbox.getTrashFolder() == null) {
                mailbox.deleteMessages(messageIds);
            } else {
                copyMoveMessages(messageIds, mailbox.getTrashFolder().getId(), true);
            }
        } catch (MessagingException e) {
            log.error(e.getMessage(), e);
            throw new GWTMessageException(e.getMessage());
        }
    }
}

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

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

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

    try {//from  w  w w . j a va2s  .  co  m
        IMailFolder currentFolder = mailbox.getCurrentFolder();
        Message msg = currentFolder.getMessageById(messageId);

        MessageHandler replyMessageHandler = MessageHandler.getInstance(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.gwtui.server.services.MailboxService.java

public void copyMoveMessages(long[] messageIds, String targetFolderId, boolean toMove) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();

    if (messageIds != null && messageIds.length > 0) {
        log.debug("copy/move " + messageIds.length + " messages...");

        try {// w  w w  .  j a v a  2 s  . com
            mailbox.copyMessages(messageIds, targetFolderId);
            log.debug("...successful");

            if (toMove) {
                mailbox.deleteMessages(messageIds);
            }
        } catch (MessagingException e) {
            log.error(e.getMessage(), e);
            throw new GWTMessageException(e.getMessage());
        }
    }
}

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

public GWTMessage openDraftMessage(long messageId) throws Exception {

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

    try {//w  w w .  j a va  2s  . com
        IMailFolder selectedFolder = mailbox.getCurrentFolder();
        Message msg = selectedFolder.getMessageById(messageId);

        MessageHandler readHandler = MessageHandler.getInstance(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.gwtui.server.services.MailboxService.java

public GWTMessage prepareForwardMessage(long messageId) throws Exception {

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

    try {/* ww  w  .ja va2s  . co  m*/
        IMailFolder currentFolder = mailbox.getCurrentFolder();
        Message msg = currentFolder.getMessageById(messageId);

        MessageHandler forardMessageHandler = MessageHandler.getInstance(mailbox.getJavaMailSession());
        forardMessageHandler.createForwardMessage(msg);

        SessionManager.get().setCurrentComposeMessage(forardMessageHandler);

        GWTMessage result = forardMessageHandler.getGWTMessage();
        result.setAttachments(forardMessageHandler.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.cubusmail.gwtui.server.services.MailboxService.java

public void markMessage(long[] messageIds, MessageListFields flagField, boolean mark) throws Exception {

    IMailbox mailbox = SessionManager.get().getMailbox();
    if (messageIds != null && messageIds.length > 0) {
        log.debug("marking " + messageIds.length + " messages...");

        try {/*w  w  w  . j a  v a2  s.  co  m*/
            IMailFolder currentFolder = mailbox.getCurrentFolder();
            for (int i = 0; i < messageIds.length; i++) {
                Message msg = currentFolder.getMessageById(messageIds[i]);
                if (flagField.equals(MessageListFields.READ_FLAG)) {
                    MessageUtils.setMessageFlag(msg, Flags.Flag.SEEN, mark);
                } else if (flagField.equals(MessageListFields.DELETED_FLAG)) {
                    MessageUtils.setMessageFlag(msg, Flags.Flag.DELETED, mark);
                } else {
                    throw new IllegalArgumentException("Unknown flag: " + flagField.name());
                }
            }
            log.debug("...successful");
        } catch (MessagingException e) {
            log.error(e.getMessage(), e);
            throw new GWTMessageException(e.getMessage());
        }
    }
}

From source file:io.hops.hopsworks.common.user.AuthController.java

/**
 * Reset password with random string and send email to user with the new password.
 *
 * @param user/*from   w w w .j  a  v  a 2  s  .  c  o  m*/
 * @param req
 * @throws MessagingException
 * @throws Exception
 */
public void resetPassword(Users user, HttpServletRequest req) throws ServiceException {
    if (user == null) {
        throw new IllegalArgumentException("User not set.");
    }
    if (userStatusValidator.isBlockedAccount(user)) {
        throw new IllegalStateException("User is blocked.");
    }
    String randomPassword = SecurityUtils.getRandomPassword(UserValidator.PASSWORD_MIN_LENGTH);
    String message = UserAccountsEmailMessages.buildTempResetMessage(randomPassword);
    try {
        emailBean.sendEmail(user.getEmail(), Message.RecipientType.TO,
                UserAccountsEmailMessages.ACCOUNT_PASSWORD_RESET, message);
    } catch (MessagingException ex) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.EMAIL_SENDING_FAILURE, Level.SEVERE,
                "user: " + user.getUsername(), ex.getMessage(), ex);
    }
    changePassword(user, randomPassword, req);
    resetFalseLogin(user);
    accountAuditFacade.registerAccountChange(user, AccountsAuditActions.RECOVERY.name(),
            UserAuditActions.SUCCESS.name(), "Password reset.", user, req);
}

From source file:emea.summit.architects.HackathlonAPIResource.java

public String sendEmailNotification(EmailPayload email) {
    try {/*  w  w w . j a  v a 2 s. c  o m*/
        String emailContent = (email.getContent() == null ? "" : email.getContent().toString());
        JavaMailService.generateAndSendEmail(emailContent.toString(), email.getSubject(),
                email.getEmailAddresses());
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "Email Failed due to " + e.getMessage();
    }
    return "Email was submitted successfully";
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_2.CFAstSMWar.CFAstSMWarRequestResetPasswordHtml.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 *//* w w  w.  java 2s.  c om*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String S_ProcName = "doPost";

    ICFAstSchemaObj schemaObj;
    HttpSession sess = request.getSession(false);
    if (sess == null) {
        sess = request.getSession(true);
        schemaObj = new CFAstSchemaObj();
        sess.setAttribute("SchemaObj", schemaObj);
    } else {
        schemaObj = (ICFAstSchemaObj) sess.getAttribute("SchemaObj");
        if (schemaObj == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "schemaObj");
        }
    }

    ICFAstSchema dbSchema = null;
    try {
        CFAstAuthorization auth = schemaObj.getAuthorization();
        if (auth != null) {
            response.sendRedirect("CFAstSMWarSecurityMainHtml");
            return;
        }

        dbSchema = CFAstSchemaPool.getSchemaPool().getInstance();
        schemaObj.setBackingStore(dbSchema);
        schemaObj.beginTransaction();
        ICFAstSecUserObj systemUser = schemaObj.getSecUserTableObj().readSecUserByULoginIdx("system");
        String passwordHash = systemUser.getRequiredPasswordHash();
        if ((passwordHash == null) || (passwordHash.length() <= 0) || passwordHash.equals("bootstrap")) {
            response.sendRedirect("CFAstSMWarSetSystemPasswordHtml");
        }

        ICFAstClusterObj resolvedCluster;
        ICFAstSysClusterObj sysCluster = schemaObj.getSysClusterTableObj().readSysClusterByIdIdx(1, false);
        if (sysCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                    "sysCluster");
        }
        resolvedCluster = sysCluster.getRequiredContainerCluster();
        if (resolvedCluster == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName,
                    "resolvedCluster");
        }
        String clusterDomainName = resolvedCluster.getRequiredFullDomainName();
        String clusterDescription = resolvedCluster.getRequiredDescription();

        String loginId = (String) request.getParameter("LoginId");
        if ((loginId == null) || (loginId.length() <= 0)) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarRequestResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("You must specify a login id to reset.");
            out.println("<p style=\"text-align:center\">");
            out.println("Enter the login you'd like to request a password reset for.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:60%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok, Request Password Reset\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Back to "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        ICFAstSecUserObj authenticatingUser = schemaObj.getSecUserTableObj().readSecUserByULoginIdx(loginId,
                true);
        if (authenticatingUser == null) {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarRequestResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">ERROR</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("Login id not found.");
            out.println("<p style=\"text-align:center\">");
            out.println("Enter the login you'd like to request a password reset for.");
            out.println("<p>");
            out.println("<center>");
            out.println("<table style=\"width:60%\">");
            out.println(
                    "<tr><th style=\"text-align:left\">Login Id:</th><td><input type=\"text\" name=\"LoginId\"/></td></tr>");
            out.println(
                    "<tr><td colspan=\"2\" style=\"text-align:center\"><button type=\"submit\" name=\"Ok, Request Password Reset\"\">Ok</button></td></tr>");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Back to "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
            return;
        }

        if (null != authenticatingUser.getOptionalPasswordResetUuid()) {

            sendPasswordResetEMail(request, authenticatingUser, resolvedCluster);

            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
            out.println("<HTML>");
            out.println("<BODY>");
            out.println("<form method=\"post\" formaction=\"CFAstSMWarRequestResetPasswordHtml\">");
            out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
            out.println("<H2 style=\"text-align:center\">INFO</H2>");
            out.println("<p style=\"text-align:center\">");
            out.println("Password reset email resent.");
            out.println("<center>");
            out.println("<table style=\"width:60%\">");
            out.println(
                    "<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Back to "
                            + clusterDescription + " Security Manager Login</A></td></tr>");
            out.println("</table>");
            out.println("</center>");
            out.println("</form>");
            out.println("</BODY>");
            out.println("</HTML>");
        }

        ICFAstClusterObj systemCluster = schemaObj.getClusterTableObj().readClusterByUDomainNameIdx("system");
        ICFAstTenantObj systemTenant = schemaObj.getTenantTableObj()
                .readTenantByUNameIdx(systemCluster.getRequiredId(), "system");
        ICFAstSecSessionObj systemSession = schemaObj.getSecSessionTableObj().newInstance();
        ICFAstSecSessionEditObj editSystemSession = (ICFAstSecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setRequiredContainerSecUser(systemUser);
        editSystemSession.setRequiredStart(Calendar.getInstance());
        systemSession = editSystemSession.create();
        editSystemSession.endEdit();

        auth = new CFAstAuthorization();
        auth.setSecCluster(systemCluster);
        auth.setSecTenant(systemTenant);
        auth.setSecSession(systemSession);
        schemaObj.setAuthorization(auth);

        ICFAstSecUserEditObj editAuthenticatingUser = authenticatingUser.beginEdit();
        editAuthenticatingUser.setOptionalPasswordResetUuid(UUID.randomUUID());
        editAuthenticatingUser.update();
        editAuthenticatingUser.endEdit();

        editSystemSession = (ICFAstSecSessionEditObj) systemSession.beginEdit();
        editSystemSession.setOptionalFinish(Calendar.getInstance());
        editSystemSession.update();
        editSystemSession.endEdit();

        schemaObj.setAuthorization(null);

        schemaObj.commit();

        sendPasswordResetEMail(request, authenticatingUser, resolvedCluster);

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
        out.println("<HTML>");
        out.println("<BODY>");
        out.println("<form method=\"post\" formaction=\"CFAstSMWarRequestResetPasswordHtml\">");
        out.println("<H1 style=\"text-align:center\">" + clusterDescription + " Security Manager</H1>");
        out.println("<H2 style=\"text-align:center\">INFO</H2>");
        out.println("<p style=\"text-align:center\">");
        out.println(
                "Password reset email sent.  Please use the links in the email to set a new password or to cancel the request.");
        out.println("<center>");
        out.println("<table style=\"width:60%\">");
        out.println("<tr><td colSpan=\"2\" style=\"text-align:center\"><A HRef=\"CFAstSMWarLoginHtml\">Back to "
                + clusterDescription + " Security Manager Login</A></td></tr>");
        out.println("</table>");
        out.println("</center>");
        out.println("</form>");
        out.println("</BODY>");
        out.println("</HTML>");
    } catch (MessagingException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught MessagingException -- " + e.getMessage(), e);
    } catch (NamingException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught NamingException -- " + e.getMessage(), e);
    } catch (RuntimeException e) {
        throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                "Caught RuntimeException -- " + e.getMessage(), e);
    } finally {
        if (dbSchema != null) {
            try {
                if (schemaObj.isTransactionOpen()) {
                    schemaObj.rollback();
                }
            } catch (RuntimeException e) {
            }
            schemaObj.setBackingStore(null);
            CFAstSchemaPool.getSchemaPool().releaseInstance(dbSchema);
        }
    }
}