Example usage for javax.mail Session getStore

List of usage examples for javax.mail Session getStore

Introduction

In this page you can find the example usage for javax.mail Session getStore.

Prototype

public Store getStore() throws NoSuchProviderException 

Source Link

Document

Get a Store object that implements this user's desired Store protocol.

Usage

From source file:org.jasig.portlet.emailpreview.dao.javamail.JavamailAccountDaoImpl.java

private Folder getUserInbox(Session session, String folderName) throws MessagingException {

    // Assertions.
    if (session == null) {
        String msg = "Argument 'session' cannot be null";
        throw new IllegalArgumentException(msg);
    }//  w  w  w  .j  a  va  2  s.  co m

    try {
        Store store = session.getStore();
        store.connect();

        if (log.isDebugEnabled()) {
            log.debug("Mail store connection established to get user inbox");
        }

        // Retrieve user's inbox folder
        Folder root = store.getDefaultFolder();
        Folder inboxFolder = root.getFolder(folderName);

        return inboxFolder;
    } catch (AuthenticationFailedException e) {
        throw new MailAuthenticationException(e);
    }

}