gpt4 book ai didi

java - EmailSender 读取响应异常

转载 作者:行者123 更新时间:2023-12-02 03:42:12 25 4
gpt4 key购买 nike

我相信我已正确遵循本网站 https://vandeneyndefilip.nu/spring-boot/spring-boot-sending-email/ 的指南,但我收到异常读取响应。

我试图在互联网上找到问题的解决方案,但我所能得到的只是将端口从 465 更改为 587。不幸的是,我从一开始就使用端口 587

  1. 这是我的应用程序属性
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=myemail@gmail.com
spring.mail.password=mypassword
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimeout=5000
  • 这是我的实现
  •             String jsonData = user.toJson();

    System.out.println(jsonData);
    byte[] arrayBlob = blobTemplate.getBytes(1, (int) blobTemplate.length());
    String data = new String(arrayBlob);

    String newData = MustacheProcessor.mustacheProcess(data, jsonData);

    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(user.getEmail());
    message.setSubject(template.getSubject());
    message.setText(newData);

    emailSender.send(message);
    } catch (MailException e) {
    e.printStackTrace();
    } catch (SQLException ex) {
    ex.printStackTrace();
    }

    我尝试查看该线路上的数据传输,一切正常

                message.setTo(user.getEmail());
    message.setSubject(template.getSubject());
    message.setText(newData);

    我已阅读跟踪,发送电子邮件时似乎出现问题

    emailSender.send(消息);

  • 这是跟踪的一半
  •   nested exception is:
    java.net.SocketException: Connection reset. Failed messages: javax.mail.MessagingException: Exception reading response;
    nested exception is:
    java.net.SocketException: Connection reset; message exception details (1) are:
    Failed message 1:
    javax.mail.MessagingException: Exception reading response;
    nested exception is:
    java.net.SocketException: Connection reset
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2460)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2187)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:740)
    at javax.mail.Service.connect(Service.java:366)
    at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:517)
    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:436)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:322)
    at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:311)
    at com.sender.tugaskp2.tugaskp2.service.impl.EmailServiceImp.sendSinglePayslip(EmailServiceImp.java:55)
    at com.sender.tugaskp2.tugaskp2.controller.EmailController.sendSinglePayslip(EmailController.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)

    最佳答案

    我通过更换我使用的网络并为我的电子邮件激活不太安全的应用程序访问来解决了这个问题。我不确定这是否是该问题的最合适答案。

    我从这个链接得到了答案 https://www.mkyong.com/spring-boot/spring-boot-how-to-send-email-via-smtp/

    祝你有美好的一天

    关于java - EmailSender 读取响应异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56829674/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com