简体   繁体   中英

No appropriate protocol (protocol is disabled or cipher suites are inappropriate). Failed messages: javax.mail.MessagingException:

I'm trying to implement the spring boot mail sender from my locale application based on smtp.gmail.com host but i get this error:

Please help me with this. I have searched many blogs, my configurations seems to be fine. Let me know If I need to change or add something.

Thanks in advance!

2022-09-11 12:17:31,499 [DEBUG] from org.springframework.web.servlet.DispatcherServlet in http-nio-1995-exec-1 - Failed to complete request: org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate). Failed messages: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate); message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
2022-09-11 12:17:31,500 [DEBUG] from org.springframework.security.web.context.SecurityContextPersistenceFilter in http-nio-1995-exec-1 - Cleared SecurityContextHolder to complete request
2022-09-11 12:17:31,501 [ERROR] from org.apache.catalina.core.ContainerBase.[Tomcat-1].[localhost].[/].[dispatcherServlet] in http-nio-1995-exec-1 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate). Failed messages: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate); message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)] with root cause
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
        at java.base/sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:172)

Mail configuration class:

@Configuration
public class MailConfig {

    @Bean
    public JavaMailSender getJavaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.gmail.com");
        mailSender.setPort(587);

        mailSender.setUsername(MyConstants.MY_EMAIL);
        mailSender.setPassword(MyConstants.MY_PASSWORD);

        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.transport.protocol", "smtp");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.debug", "true");

        return mailSender;
    }

}

Constants class:

public class MyConstants {

    public static final String MY_EMAIL = "myMail@gmail.com";
    public static final String MY_PASSWORD = "passwordGeneretedFromGmail";
    public static final String FRIEND_EMAIL = "senderToMail@gmail.com";

}

My Controller class:

 @Controller
    @RequestMapping("/api")
    public class SimpleEmailExampleController {
    
        @Autowired
        public JavaMailSender emailSender;
    
        @ResponseBody
        @RequestMapping("/sendSimpleEmail")
        public String sendSimpleEmail() {
    
            // Create a Simple MailMessage.
            SimpleMailMessage message = new SimpleMailMessage();
    
            message.setTo(MyConstants.FRIEND_EMAIL);
            message.setSubject("Test Simple Email");
            message.setText("Hello, Im testing Simple Email");
    
            // Send Message!
            this.emailSender.send(message);
    
            return "Email Sent!";
        }
    
    }

Resolved by adding this line in the main application of spring boot:

java.security.Security.setProperty("jdk.tls.disabledAlgorithms", "");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question No appropriate protocol (protocol is disabled or cipher suites are inappropriate) javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) without handshake Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) in java 11.0.9 handling exception: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate Exception: SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) Postfix and OpenJDK 11: "No appropriate protocol (protocol is disabled or cipher suites are inappropriate)" Getting errors when running Splunk SDK examples: “No appropriate protocol (protocol is disabled or cipher suites are inappropriate)” Keycloak 7.0.1 and MySQL (RDS) SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) for review JDK-11 SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM