Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29755

Java mail cannot connect to smtp using tls or ssl

$
0
0

0

I am trying to connect to a mail server from Java. I have been able to successfully connect to many mail servers from Java using the same code, including Gmail, Rackspace, GoDaddy, and others, but this one does not work no matter the settings I try.

    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", this.outgoingHost);
    props.put("mail.smtp.port", 587);
    props.put("mail.smtp.ssl.trust", this.outgoingHost);
    session = Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });

This fails with, javax.mail.MessagingException: Could not convert socket to TLS; nested exception is: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

I also tried,

    props.put("mail.smtp.host", this.outgoingHost);
    props.put("mail.smtp.port", 587);
    props.put("mail.smtp.socketFactory.port", 587);
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.ssl.trust", this.outgoingHost);
    session = Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }
    });

This fails with, javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 550 SMTP AUTH is required for message submission on port 587

I also tried port 465, but it gets a timeout.

I was able to send mail using the same smtp settings from Thunderbird email client (same host/port/user/pw, but it must be doing something else).

Using Java Mail 1.51

Any ideas?


Viewing all articles
Browse latest Browse all 29755

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>