簡體   English   中英

沒有合適的協議(協議被禁用或密碼套件不合適)。 失敗的消息:javax.mail.MessagingException:

[英]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:

請幫我解決一下這個。 我搜索了很多博客,我的配置似乎很好。 如果我需要更改或添加某些內容,請告訴我。

提前致謝!

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)

郵件配置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;
    }

}

常數 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";

}

我的 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!";
        }
    
    }

通過在 spring 引導的主應用程序中添加這一行來解決:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM