Javamail security exception

From: news (qiang.zhao_at_geniewave.com)
Date: 10/31/03


Date: Fri, 31 Oct 2003 16:40:26 GMT

I want to connect a email server with ssl security. I am using the attched
code, but I get the following exception:
             javax.mail.MessagingException: DummySSLSocketFactory;
                   nested exception is:
             java.net.SocketException: DummySSLSocketFactory
             at
com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:335)
             at javax.mail.Service.connect(Service.java:233)
             at javax.mail.Service.connect(Service.java:134)
             at
com.geniewave.mail.slave.server.SimpleReceiver.receive(SimpleReceiver.java:5
5)
             at
com.geniewave.mail.slave.server.SimpleReceiver.main(SimpleReceiver.java:26)
Could someone help me with that? Thank you very much. Here is the code

private static void setProperties(Properties props)
    {
      Security.addProvider( new com.sun.net.ssl.internal.ssl.Provider());
      Security.setProperty( "ssl.SocketFactory.provider",
"DummySSLSocketFactory");
      final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
      // IMAP provider
      props.setProperty( "mail.imap.socketFactory.class", SSL_FACTORY);
      props.setProperty( "mail.imap.socketFactory.fallback", "false");
      props.setProperty( "mail.imap.port", "993");
      props.setProperty( "mail.imap.socketFactory.port", "993");
    }

public static void receive(String popServer, String popUser
   , String popPassword)
  {
  Store store=null;
    Folder folder=null;
    try
    {
      // -- Get hold of the default session --
      Properties props = System.getProperties();
      setProperties(props);
      props.put("mail.debug","true");
      Session session = Session.getInstance(props, null);

      // -- Get hold of a POP3 message store, and connect to it --
      store = session.getStore("imap");
      store.connect(popServer, popUser, popPassword);

      // -- ...and its INBOX --
      folder = store.getFolder("INBOX");
      if (folder == null) throw new Exception("No POP3 INBOX");

      // -- Open the folder for read only --
      folder.open(Folder.READ_ONLY);
      Message[] msg = folder.getMessages();
      int count = folder.getMessageCount();
      for (int i = 0; i < count; i++)
      {
        String[] froms = msg[i].getHeader("From");
        System.out.println(( (InternetAddress)
msg[i].getFrom()[0]).getAddress());
        String to = "";
    Address[] tos = msg[i].getRecipients(Message.RecipientType.TO);
    for(int j=0;j<tos.length; j++)
    {
      to += ((InternetAddress)(tos[j])).getAddress();
    }

System.out.println(((InternetAddress)(msg[i].getRecipients(Message.Recipient
Type.TO))[0]).getAddress());;
        printMessage(msg[i]);
      }

    }
    catch (Exception ex)
    {
      ex.printStackTrace();
    }
    finally
    {
      // -- Close down nicely --
      try
      {
        if (folder!=null) folder.close(false);
        if (store!=null) store.close();
      }
      catch (Exception ex2) {ex2.printStackTrace();}
    }
  }



Relevant Pages

  • SSLSocket Exception in javamail
    ... I want to connect a email server with ssl security. ... but I get the following exception: ... public static void receive(String popServer, String popUser ...
    (comp.lang.java.programmer)
  • I need javamail help
    ... I want to connect a email server with ssl security. ... but I get the following exception: ... public static void receive(String popServer, String popUser ...
    (comp.lang.java.programmer)
  • Re: I need javamail help
    ... but I get the following exception: ... > public static void receive(String popServer, String popUser ... >, String popPassword) ...
    (comp.lang.java.programmer)
  • Re: Fastest way to split a file by columns?
    ... ByteBuffer buf = new ByteBuffer; ... // process exception. ... static void initializeStream() throws Exception { ... if (pos>= buf.length) { ...
    (comp.lang.java.programmer)
  • Re: Threading
    ... now I see why I was sceptic about the thread abort exception. ... tried a similar scenario in the default domain. ... static void ThreadProc() ...
    (microsoft.public.dotnet.languages.csharp)