Example usage for javax.mail AuthenticationFailedException getCause

List of usage examples for javax.mail AuthenticationFailedException getCause

Introduction

In this page you can find the example usage for javax.mail AuthenticationFailedException getCause.

Prototype

@Override
public synchronized Throwable getCause() 

Source Link

Document

Overrides the getCause method of Throwable to return the next exception in the chain of nested exceptions.

Usage

From source file:com.clustercontrol.jobmanagement.util.SendApprovalMail.java

/**
 * ?????/*from   www.jav  a  2 s  .  c  o m*/
 * 
 * @param jobInfo
 *            
 * @param subject
 *            ??
 * @param content
 *            
 */
private void sendMail(JobInfoEntity jobInfo, String subject, String content, String approvalRequestUser)
        throws HinemosUnknown {
    m_log.debug("sendMail()");

    m_log.debug("sendMail() subject:" + subject);
    m_log.debug("sendMail() content:" + content);

    try {
        ArrayList<String> toAddressList = new ArrayList<String>();

        String userId = null;
        List<String> userIdList = null;
        String addr;

        userId = jobInfo.getApprovalReqUserId();
        if (userId != null && !userId.equals("*")) {
            addr = getUserMailAdress(userId);
            if (addr != null) {
                toAddressList.add(addr);
            }
        } else {
            userIdList = UserRoleCache.getUserIdList(jobInfo.getApprovalReqRoleId());
            if (userIdList != null && !userIdList.isEmpty()) {
                for (String user : userIdList) {
                    addr = null;
                    addr = getUserMailAdress(user);
                    if (addr != null) {
                        toAddressList.add(addr);
                    }
                }
            }
        }

        if (approvalRequestUser != null && !approvalRequestUser.equals("")) {
            addr = null;
            addr = getUserMailAdress(approvalRequestUser);
            if (addr != null) {
                toAddressList.add(addr);
            }
        }
        // ????????
        if (toAddressList.size() == 0) {
            m_log.debug("sendMail() : mail address is empty");
            internalEventNotify(PriorityConstant.TYPE_INFO, jobInfo.getId().getSessionId(),
                    jobInfo.getId().getJobId(), MessageConstant.MESSAGE_SYS_019_JOB, null);
            return;
        }
        String[] toAddress = toAddressList.toArray(new String[0]);

        try {
            this.sendMail(toAddress, null, subject, content);
        } catch (AuthenticationFailedException e) {
            String detailMsg = "cannot connect to the mail server due to an Authentication Failure";
            m_log.warn("sendMail() " + e.getMessage() + " : " + detailMsg + " : " + e.getClass().getSimpleName()
                    + ", " + e.getMessage());
            internalEventNotify(PriorityConstant.TYPE_CRITICAL, jobInfo.getId().getSessionId(),
                    jobInfo.getId().getJobId(), MessageConstant.MESSAGE_SYS_020_JOB, null);
        } catch (SMTPAddressFailedException e) {
            String detailMsg = e.getMessage() + "(SMTPAddressFailedException)";
            m_log.warn("sendMail() " + e.getMessage() + " : " + detailMsg + " : " + e.getClass().getSimpleName()
                    + ", " + e.getMessage());
            internalEventNotify(PriorityConstant.TYPE_CRITICAL, jobInfo.getId().getSessionId(),
                    jobInfo.getId().getJobId(), MessageConstant.MESSAGE_SYS_020_JOB, null);
        } catch (MessagingException e) {
            String detailMsg = e.getCause() != null ? e.getMessage() + " Cause : " + e.getCause().getMessage()
                    : e.getMessage();
            m_log.warn("sendMail() " + e.getMessage() + " : " + detailMsg + " : " + e.getClass().getSimpleName()
                    + ", " + e.getMessage());
            internalEventNotify(PriorityConstant.TYPE_CRITICAL, jobInfo.getId().getSessionId(),
                    jobInfo.getId().getJobId(), MessageConstant.MESSAGE_SYS_020_JOB, null);
        } catch (UnsupportedEncodingException e) {
            String detailMsg = e.getCause() != null ? e.getMessage() + " Cause : " + e.getCause().getMessage()
                    : e.getMessage();
            m_log.warn("sendMail() " + e.getMessage() + " : " + detailMsg + detailMsg + " : "
                    + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
            internalEventNotify(PriorityConstant.TYPE_CRITICAL, jobInfo.getId().getSessionId(),
                    jobInfo.getId().getJobId(), MessageConstant.MESSAGE_SYS_020_JOB, null);
        }
    } catch (RuntimeException e1) {
        String detailMsg = e1.getCause() != null ? e1.getMessage() + " Cause : " + e1.getCause().getMessage()
                : e1.getMessage();
        m_log.warn("sendMail() " + e1.getMessage() + " : " + detailMsg + detailMsg + " : "
                + e1.getClass().getSimpleName() + ", " + e1.getMessage(), e1);
        internalEventNotify(PriorityConstant.TYPE_CRITICAL, jobInfo.getId().getSessionId(),
                jobInfo.getId().getJobId(), MessageConstant.MESSAGE_SYS_020_JOB, null);
    }
}

From source file:org.xwiki.contrib.mail.internal.DefaultMailReader.java

/**
 * {@inheritDoc}/*from  ww  w.  j  a v  a2s  .c  o  m*/
 * 
 * @see org.xwiki.contrib.mail.IMailReader#check(java.lang.String, int, java.lang.String, java.lang.String,
 *      java.lang.String, java.lang.String, boolean)
 */
@Override
public int check(final String folder, final boolean onlyUnread) {
    int result;
    boolean toClose = true;

    // If store is currently connected, we don't need to close it after the check.
    // If it is not, we close it after to leave everything as it was.
    if (store != null && store.isConnected()) {
        toClose = false;
    }

    try {

        List<Message> messages = read(folder, onlyUnread);

        result = messages.size();

        // FIXME: instead of converting exceptions to int code, would be better to create new Exception class
        // (like MailException) with provided error code, message and inner stacktrace, and present that to UI.
    } catch (AuthenticationFailedException e) {
        logger.warn("checkMails : ", e);
        return SourceConnectionErrors.AUTHENTICATION_FAILED.getCode();
    } catch (FolderNotFoundException e) {
        logger.warn("checkMails : ", e);
        return SourceConnectionErrors.FOLDER_NOT_FOUND.getCode();
    } catch (MessagingException e) {
        logger.warn("checkMails : ", e);
        if (e.getCause() instanceof java.net.UnknownHostException) {
            return SourceConnectionErrors.UNKNOWN_HOST.getCode();
        } else {
            return SourceConnectionErrors.CONNECTION_ERROR.getCode();
        }
    } catch (IllegalStateException e) {
        return SourceConnectionErrors.ILLEGAL_STATE.getCode();
    } catch (Throwable t) {
        logger.warn("checkMails : ", t);
        return SourceConnectionErrors.UNEXPECTED_EXCEPTION.getCode();
    }
    if (toClose) {
        close();
    }
    logger.debug("checkMails : " + result + " available from " + getMailSource().getHostname());

    return result;
}