我正在尝试基于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!";
}
}发布于 2022-09-11 11:34:51
通过在spring引导的主要应用程序中添加这一行来解决问题:
java.security.Security.setProperty("jdk.tls.disabledAlgorithms",“);
https://stackoverflow.com/questions/73678833
复制相似问题