I am using simple-java-mail API which is a wrapper on top of JavaMail API. I am sending emails with my Gmail account credentials. I am mentioning what I am able to do and what not with this.
I am able to send emails perfectly with the following settings and properties.
boolean enableSSL = true;
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", 465);
props.put("mail.smtp.auth", "true"); //enable authentication
props.put("mail.smtp.ssl.enable", enableSSL);
If(enableSSL == true)
transportStrategy = TransportStrategy.SMTP_SSL;
I am not able to send emails with plain SMTP.
boolean enableSSL = false;
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", 25);
if(enableSSL == false)
transportStrategy = TransportStrategy.SMTP_PLAIN;
I am not able to send emails with TLS settings.
boolean enableSSL = true;
boolean enableTLS = true;
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", 587);
props.put("mail.smtp.auth", "true"); //enable authentication
props.put("mail.smtp.ssl.enable", enableSSL);
props.put("mail.smtp.starttls.enable", true);
If(enableSSL == true && enableTLS == true)
transportStrategy = TransportStrategy.SMTP_TLS;
What should I do apart from these configuration properties? with settings smtp.gmail.com:25, code is not working at all. With smtp.gmail.com:465 and enableSSL = true, code is working like charm.
But TLS is not working. I am attaching what error I am getting in all the 3 cases.
Thanks,