Results 1 to 2 of 2
  1. #1
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    47
    Rep Power
    0

    Unhappy e-mail messenger can not convert socket to TLS

    i decided to create custom socketFactory so my program is:
    Java Code:
            Properties properties = (Properties)System.getProperties().clone();
            properties.put("mail.transport.protocol", "smtp");
            properties.put("mail.smtp.timeout" , "5000");
            properties.put("mail.smtp.host", currentSettingsDocument.getSMTPHostServer());
            properties.put("mail.smtp.port", currentSettingsDocument.getSMTPPort());
            properties.put("mail.smtp.auth", "true");
            properties.put("mail.smtp.ssl.trust", currentSettingsDocument.getSMTPHostServer());
            //properties.put("mail.debug", "true");
    		
            properties.put("mail.smtp.socketFactory.port", currentSettingsDocument.getSMTPPort());
    
           properties.put("mail.smtp.socketFactory.class", "DummySSLSocketFactory");
            
           properties.put("mail.smtp.socketFactory.fallback", "false");
    
            
            switch (currentSettingsDocument.getEncryption())
            {
                case TLS:
                    properties.put("mail.smtp.starttls.enable", "true");
                    break;
    
                case SSL:
                    properties.put("mail.smtp.socketFactory.port", currentSettingsDocument.getSMTPPort());
                    properties.put("mail.smtp.socketFactory.class",
                            "javax.net.ssl.SSLSocketFactory");
                    break;
                case NONE:
                    break;
            }
    
            Authenticator authenticator = new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(currentSettingsDocument.getLogin() , currentSettingsDocument.getPassword());
                }
            };
    
            properties.put("mail.smtp.starttls.enable", "true");
    
            Session session = Session.getInstance(properties,authenticator);
    
            MimeMessage message = new MimeMessage(session);
    
            message.setFrom(new InternetAddress(currentSettingsDocument.getSenderMail()));
    
            for(InternetAddress addr: recepients )
            message.addRecipient(Message.RecipientType.TO, addr );
    
    
            message.setText(data);
    after compiling i receive :
    Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
    nested exception is:
    java.io.IOException: Couldn't connect using unknown socket factory to host, port: smtp.gmail.com, -1; Exception: java.lang.ClassNotFoundException: DummySSLSocketFactory
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTra nsport.java:1972)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SM TPTransport.java:642)
    at javax.mail.Service.connect(Service.java:295)
    at XMailMessenger.MailMessenger.sendMail(MailMessenge r.java:372)
    at alfa.runner.main(runner.java:64)
    I brought DummySSLSocketFactory class from Oracle FAQ site and put it in my folder, where java code above is situated.
    And i dont understand, why it is necessary to include SSSLSocketFactory in my TLS connection to Google SMTP-server.
    Please, help me to solve ClassNotFound exception!

    PS dont ask me why i am using Dummy classes, it because of the other exception

  2. #2
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    47
    Rep Power
    0

    Default Re: e-mail messenger can not convert socket to TLS

    Everything ok if this function not static!

Similar Threads

  1. Replies: 0
    Last Post: 11-06-2012, 08:27 AM
  2. problem with sending mail usin javaX.mail api
    By sandeepsai39 in forum New To Java
    Replies: 4
    Last Post: 11-25-2009, 05:37 AM
  3. Replies: 2
    Last Post: 07-25-2009, 09:36 AM
  4. Replies: 2
    Last Post: 05-05-2008, 06:01 AM
  5. Sending a mail with the local mail program
    By thedude in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2007, 12:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •