I have written the following code for sending email using javamail API through SMTP as TLS as SSL is not supported but I ended up with the following exception. Please see my
The stack trace reveals that the actual cause of the problem is this:
java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
You are running into a limitation of older versions of Java that did not support DH primes longer than 1024 bits, which your SMTP server was probably requiring. Here are the relevant bug entries:
This restriction/limitation was removed in Java 8 (see the release notes).
Note that as has been pointed out already, your "fix" of disabling STARTTLS is not a real fix: It means your password will be sent as plain text, plus this will only work for SMTP servers that allow unencrypted traffic on port 587.
session.getProperties().put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.ssl.trust", "smtp.office365.com(site where your account is)");
props.put("mail.smtp.starttls.enable", true);
These codes should be able to start a ttls communication and get the mail service running.
In addition to this the antivirus creates a firewall that stops the handshake from happening.
I resolved this issue by just commenting the below property
props.put("mail.smtp.starttls.enable", "true");
and the code got executed with no errors or warning or simply delete this line from the above source code. It is working like a charm till date.
I resolved this issue by disabling my virus guard.
I had a same issue with smtp.gmail.com and fixed with the following steps
Make sure your antivirus software is not blocking the application. In my case Avast was blocking me from sending e-mails in a Java SE application.