Unable to send an email using SMTP (Getting javax.mail.MessagingException: Could not convert socket to TLS;)

前端 未结 11 1900
北恋
北恋 2020-12-10 12:04

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

11条回答
  •  情话喂你
    2020-12-10 12:27

    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:

    • http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6521495
    • http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7044060

    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.

提交回复
热议问题