2 Replies Latest reply on Jan 18, 2013 2:00 AM by 984643

    javamail getStore("imap") or getStore("imaps")

      I am using Javamail-1.4.5 to program for receive mail from several address on Imap server.
      some of the mail address need SSL,some need not,my code as following:

      Properties prop = new Properties();

      prop.setProperty("mail.imap.host", imapserver);

      prop.setProperty("mail.imap.auth.plain.disable", "true");

      if(isSsl == true){
           prop.setProperty("mail.imap.port", sslPort!=null&&sslPort.length()>0?sslPort:"993");
           prop.setProperty("mail.imap.ssl.enable", "true");

      Session mailsession=Session.getInstance(prop,null);

      session = mailsession;


      store = (IMAPStore)mailsession.getStore("imap");

      my problem is:
      when connect to imap server over SSL,need i to use following code to get IMAPSStore?
      store = (IMAPSStore)mailsession.getStore("imaps");

      looking forward to your answer!thanks!
        • 1. Re: javamail getStore("imap") or getStore("imaps")
          Bill Shannon-Oracle
          There's two different approaches...

          1. Switch the protocol you're using from "imap" to "imaps" depending on whether you want SSL or not.
          Note that you'll also need to adjust the names of the properties you're setting to be "mail.imap.*" or

          2. Always use the "imap" protocol, and turn on use of SSL by setting the "mail.imap.ssl.enable"
          property to "true".

          In neither case should you need to set the "port" property; the correct default port will be chosen based
          on whether you're using SSL or not.

          Also, unless you're using methods specific to the IMAPStore class, you don't need to cast the returned
          Store object to an IMAPStore object. Most of the time just using the Store API is sufficient.
          • 2. Re: javamail getStore("imap") or getStore("imaps")
            Thanks a lot! The answer is very useful for me!