Package javax.mail

Examples of javax.mail.Store


    try
    {
      // login to the IMAP server
      Properties props = new Properties();
      Session session = Session.getInstance(props, null);
      Store store = session.getStore("imap");
      store.connect(_server, _username, _password);
      setStore(store);

      setRootFolders(FolderData.toFolderData(this, store.getDefaultFolder().list()));

      // TODO: Add logged in indicator to restrict access

      _gotoFolder(null);
View Full Code Here


            session.setAttribute(MailContext.SESSION_MAIL_CONTEXT, mailContext);
        }

        // assert mailSession is available
        javax.mail.Session mailSession;
        Store mailStore;
        try {
            try {
                mailSession = (javax.mail.Session) mailContext.get(MailContext.MAIL_SESSION_ENTRY);
            } catch (ContextException ce) {
                // build session properties
                Properties sessionProperties = new Properties();
                String[] allParameterNames = par.getNames();
                for (int i = 0; i < allParameterNames.length; i++) {
                    String parameterName = allParameterNames[i];
                    final String PARAMETER_NAME_PREFIX = "javax.mail.Session.props:";
                    if (parameterName.startsWith(PARAMETER_NAME_PREFIX)) {
                        String sessionPropName = parameterName.substring(PARAMETER_NAME_PREFIX.length());
                        String sessionPropValue = par.getParameter(parameterName, null);
                        if (sessionPropValue != null) {
                            getLogger().debug("Add session property " +
                                    String.valueOf(sessionPropName) + ": " +
                                    String.valueOf(sessionPropValue));
                            sessionProperties.put(sessionPropName, sessionPropValue);
                        }
                    }
                }
                mailSession = javax.mail.Session.getDefaultInstance(sessionProperties, null);
                checkProviders(mailSession);
                mailContext.put(MailContext.MAIL_SESSION_ENTRY, mailSession);
            }
        } catch (Exception e) {
            String message = "Cannot create mail session";
            getLogger().error(message, e);
            throw new ProcessingException(message, e);
        }

        // assert mailStore is available
        String storeURLNameExpanded = null;
        String storeURLNameTemplate = par.getParameter("store-urlname", null);
        try {
            try {
                mailStore = (Store) mailContext.get(MailContext.MAIL_STORE_ENTRY);
            } catch (ContextException ce) {

                // imap://{userid}:{password}@host:port/
                storeURLNameExpanded = getURLNameExpanded(storeURLNameTemplate, userid, password);

                URLName urlNameExpanded = new URLName(storeURLNameExpanded);
                getLogger().info("get store using URLName " + String.valueOf(urlNameExpanded));
                mailStore = mailSession.getStore(urlNameExpanded);
                mailStore.connect();
                mailContext.put(MailContext.MAIL_STORE_ENTRY, mailStore);
            }
        } catch (Exception e) {
            String message = "Cannot get store, and connect " + String.valueOf(storeURLNameExpanded);
            getLogger().error(message, e);
View Full Code Here

            try {
                folder = (Folder) getFolder(folderName);
            } catch (ContextException ce) {
                // folder is not stored yet

                Store store = (Store) get(MAIL_STORE_ENTRY);
                // get folder, eventually connect the store
                try {
                    if (!store.isConnected()) {
                        store.connect();
                    }
                    final String DEFAULT_FOLDER_NAME = "~";

                    // empty folder name is specified by empty string, or "~"
                    if (folderName.equals(DEFAULT_FOLDER_NAME) || folderName.length() == 0) {
                        folder = store.getDefaultFolder();
                    } else {
                        folder = store.getFolder(folderName);
                    }

                    // save the Folder, for later access
                    putFolder(folder);
                } catch (MessagingException me) {
View Full Code Here

    public void generate()
    throws SAXException, ProcessingException {

        try {
            Session sess = Session.getDefaultInstance(this.props, null);
            Store st = sess.getStore("imap");

            log("Connecting to IMAP server @ " + this.host);
            st.connect(this.host, this.user, this.pass);

            log("Attempting to open default folder");
            Folder f = st.getFolder("inbox");

            f.open(Folder.READ_WRITE);

            log("Downloading message list from folder");
            this.message = f.getMessages();
View Full Code Here

*/
public class JavaMailConnection extends JavaMailSenderImpl {

    public Folder getFolder(String protocol, String folderName) {
        try {
            Store store = getSession().getStore(protocol);
            store.connect(getHost(), getPort(), getUsername(), getPassword());
            return store.getFolder(folderName);
        } catch (MessagingException e) {
            throw new MailSendException("Mail server connection failed", e);
        }
    }
View Full Code Here

    final String HEADER_EVALUATION_PUBLISH = "TEAMMATES: Evaluation Published: %s %s";
    final String TEAMMATES_APP_URL = "You can view the result here: " + Config.inst().TEAMMATES_LIVE_SITE;
    final String TEAMMATES_APP_SIGNATURE = "If you encounter any problems using the system, email TEAMMATES support";

    Session sessioned = Session.getDefaultInstance(System.getProperties(), null);
    Store store = sessioned.getStore("imaps");
    store.connect("imap.gmail.com", gmail, password);

    // Retrieve the "Inbox"
    Folder inbox = store.getFolder("inbox");
    // Reading the Email Index in Read / Write Mode
    inbox.open(Folder.READ_WRITE);
    FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    Message messages[] = inbox.search(ft);
    System.out.println(messages.length + " unread message");
View Full Code Here

    final String TEAMMATES_APP_URL = "You can view the result here: "
        + Config.inst().TEAMMATES_LIVE_SITE;
    final String TEAMMATES_APP_SIGNATURE = "If you encounter any problems using the system, email TEAMMATES support";

    Session sessioned = Session.getDefaultInstance(System.getProperties(), null);
    Store store = sessioned.getStore("imaps");
    store.connect("imap.gmail.com", gmail, password);

    // Retrieve the "Inbox"
    Folder inbox = store.getFolder("inbox");
    // Reading the Email Index in Read / Write Mode
    inbox.open(Folder.READ_WRITE);
    FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    Message messages[] = inbox.search(ft);
    System.out.println(messages.length + " unread message");
View Full Code Here

   */
  public static String getRegistrationKeyFromGmail(String gmail,
      String password, String courseId) {
    Session sessioned = Session
        .getDefaultInstance(System.getProperties(), null);
    Store store = null;
    try {
      store = sessioned.getStore("imaps");
    } catch (NoSuchProviderException e) {
      e.printStackTrace();
    }
    try {
      store.connect("imap.gmail.com", gmail, password);
    } catch (MessagingException e) {
      e.printStackTrace();
    }

    try {
      // Retrieve the "Inbox"
      Folder inbox = store.getFolder("inbox");
      // Reading the Email Index in Read / Write Mode
      inbox.open(Folder.READ_WRITE);
      FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
      Message messages[] = inbox.search(ft);

View Full Code Here

   */
  public static String getEvaluationReminderFromGmail(String gmail,
      String password, String courseId, String evalId) throws Exception {
    Session sessioned = Session.getDefaultInstance(System.getProperties(),
        null);
    Store store = sessioned.getStore("imaps");
    store.connect("imap.gmail.com", gmail, password);

    // Retrieve the "Inbox"
    Folder inbox = store.getFolder("inbox");
    // Reading the Email Index in Read / Write Mode
    inbox.open(Folder.READ_WRITE);
    FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    Message messages[] = inbox.search(ft);

View Full Code Here

   */
  public static void markAllEmailsSeen(String username, String password)
      throws Exception {
    Session sessioned = Session.getDefaultInstance(System.getProperties(),
        null);
    Store store = sessioned.getStore("imaps");
    store.connect("imap.gmail.com", username, password);

    // Retrieve the "Inbox"
    Folder inbox = store.getFolder("inbox");
    // Reading the Email Index in Read / Write Mode
    inbox.open(Folder.READ_WRITE);

    FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
    Message messages[] = inbox.search(ft);
View Full Code Here

TOP

Related Classes of javax.mail.Store

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.