spring-data-jpa 没有合适的协议(协议被禁用或密码套件不合适),失败消息:javax.mail.MessagingException:

chhqkbe1  于 2022-11-10  发布在  Spring
关注(0)|答案(1)|浏览(224)

我尝试从基于www.example.com主机的本地应用程序实现Sping Boot 邮件发送器smtp.gmail.com,但收到以下错误:
请帮我这个。我已经搜索了许多博客,我的配置似乎是罚款。让我知道,如果我需要改变或添加一些东西。
提前感谢!

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)

邮件配置类:

@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;
    }

}

常量类:

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

    }
but5z9lq

but5z9lq1#

通过在 Spring Boot 的主应用程序中添加以下行解决:
“安全性”属性的值为“安全性”;

相关问题