Results 1 to 1 of 1

Thread: Java Mail Issue

  1. #1
    rdcian is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Question Java Mail Issue

    I have read many posts from many people and haven't been able to figure out what is going on.

    My problem is shown below, why am I getting this error message?

    The code I am using
    Java Code:
    import java.io.IOException;
    import java.io.InputStream;
    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;
    
    /**
     *
     */
    public class Email {
    
        private String SMTP_HOST_NAME;
        private String SMTP_EMAIL;
        private String SMTP_USER;
        private String SMTP_PWD, SMTP_PORT;
    
        public Email(){
            
            Properties prop = new Properties();
            
            try {
                
                InputStream is = getClass().getResourceAsStream("manage/PROPERTIES.properties");
                
                prop.load(is);
                
            } catch (IOException ex) {
                
            }
            
            SMTP_HOST_NAME = prop.getProperty("SMTP.HOST.NAME");
            SMTP_USER = prop.getProperty("SMTP.EMAIL.USER");
            SMTP_PWD = prop.getProperty("SMTP.EMAIL.PASSWORD");
            SMTP_EMAIL = prop.getProperty("SMTP.EMAIL");
            SMTP_PORT = prop.getProperty("SMTP.PORT");
            
        }
    
        public void postMail(String recipient, String subject,
                String message) throws MessagingException {
            boolean debug = false;
    
            //Set the host smtp address
            Properties props = System.getProperties();
            
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", SMTP_HOST_NAME);
            props.put("mail.smtp.port", SMTP_PORT);
            
            props.put("mail.smtp.socketFactory.port", "26");
            
    	props.put("mail.smtp.socketFactory.class",
    				"javax.net.ssl.SSLSocketFactory");
            
            Authenticator auth = new SMTPAuthenticator();
            Session session = Session.getDefaultInstance(props, auth);
    
            session.setDebug(debug);
    
            // create a message
            Message msg = new MimeMessage(session);
    
            // set the from and to address
            InternetAddress addressFrom = new InternetAddress(SMTP_EMAIL);
            msg.setFrom(addressFrom);
    
            InternetAddress[] addressTo = new InternetAddress[1];
            
            addressTo[0] = new InternetAddress(recipient);
            
            msg.setRecipients(Message.RecipientType.TO, addressTo);
    
            // Setting the Subject and Content Type
            msg.setSubject(subject);
            msg.setContent(message, "text/plain");
            Transport.send(msg);
        }
    
        /**
         * SimpleAuthenticator is used to do simple authentication
         * when the SMTP server requires it.
         */
        private class SMTPAuthenticator extends javax.mail.Authenticator {
    
            public PasswordAuthentication getPasswordAuthentication() {
                String username = SMTP_USER;
                String password = SMTP_PWD;
                return new PasswordAuthentication(username, password);
            }
        }
    The Error I am getting

    Java Code:
    javax.mail.MessagingException: Could not connect to SMTP host: mail.something.com, port: 26;
      nested exception is:
    	javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
    	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934)
    	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    	at javax.mail.Service.connect(Service.java:317)
    	at javax.mail.Service.connect(Service.java:176)
    	at javax.mail.Service.connect(Service.java:125)
    	at javax.mail.Transport.send0(Transport.java:194)
    	at javax.mail.Transport.send(Transport.java:124)

    Information I was given for the server:

    server name for both incoming and outgoing email: mail.somethin.com
    username: someone@something.com
    Password: *******
    Outgoing port 26
    Incoming port POP3 110

    Thanks for helping me. Hopefully I am not crazy
    Last edited by rdcian; 10-19-2012 at 08:22 AM.

Similar Threads

  1. trying to sendin mail with java mail api
    By akhilsrivastava in forum Advanced Java
    Replies: 1
    Last Post: 04-04-2012, 09:34 PM
  2. send mail via java without java mail API
    By majidvadoostan in forum Networking
    Replies: 2
    Last Post: 04-26-2011, 09:30 PM
  3. Replies: 2
    Last Post: 07-25-2009, 09:36 AM
  4. Replies: 2
    Last Post: 06-04-2009, 01:42 PM
  5. Replies: 2
    Last Post: 05-05-2008, 06:01 AM

Posting Permissions

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