首页 > 解决方案 > 从自定义后缀服务器发送的 Spring Boot 电子邮件不起作用

问题描述

好吧,我正在尝试使用 Spring Boot 部署 API 服务。当我开始使用他们的邮件服务器(Zentyal postfix 邮件服务器)进行生产设置时,问题就来了。系统是具有 API 服务的虚拟机,需要从父服务器发送电子邮件。我在电子邮件文档中尝试了很多东西,但没有任何效果(开发人员的 Gmail 设置工作正常)。

application.properties的是这个

spring.mail.host=199.14.10.242
spring.mail.port=587
spring.mail.username=pruebasmail@enterprise.com
spring.mail.password=password
spring.mail.properties.mail.smtp.auth:true
spring.mail.properties.mail.smtp.starttls.enable:true
spring.mail.properties.mail.smtp.starttls.required:true
spring.mail.properties.mail.smtp.ssl.enable=true
mail.smtp.starttls.enable=false
spring.mail.properties.mail.smtp.socketFactory.port=587

这是我的方法。

private void sendEmailGeneric(String textMessage, String email, String subject, List<HashMap<String, String>> attachmentPaths, MimeMessage message, MimeMessageHelper helper) {
       
        try {
            helper.setTo(email);
            helper.setText(textMessage, true);
            helper.setSubject(subject);
            for (HashMap<String, String> attachmentPath : attachmentPaths) {
                FileSystemResource file = new FileSystemResource(new File(attachmentPath.get("file_path")));
                helper.addAttachment(attachmentPath.get("file_name"), file);
            }
            sender.send(message);
        } catch (MessagingException e) {
            LOGGER.error("Hubo un error al enviar el mail: {}", e);
        }
    }

所以,正如我所说的,Gmail 工作正常,关键是春季发送的电子邮件是正确的,所有邮件都已发送。问题从邮件服务器开始。这是我发送邮件时的日志图片。

在此处输入图像描述

我从电子邮件服务器中唯一知道的是 Zentyal 服务器,并且正在使用 postfix,我现在正在配置盲目,因为他们对他们的信息感到嫉妒。他们给了我一个可以工作和发送电子邮件的 python 代码,但 spring boot 不是,如果你们有任何可能的解决方案,我将不胜感激。

编辑:

我再次测试,现在日志向我发送了这个:

2020-12-03 13:01:53.539 ERROR 210981 --- [http-nio-3000-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : 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: Could not connect to SMTP host: 199.14.10.242, port: 587;
  nested exception is:
        javax.net.ssl.SSLException: Unsupported or unrecognized SSL message. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: 199.14.10.242, port: 587;
  nested exception is:
        javax.net.ssl.SSLException: Unsupported or unrecognized SSL message; message exceptions (1) are:
Failed message 1: javax.mail.MessagingException: Could not connect to SMTP host: 199.14.10.242, port: 587;
  nested exception is:
        javax.net.ssl.SSLException: Unsupported or unrecognized SSL message] with root cause

javax.net.ssl.SSLException: Unsupported or unrecognized SSL message
        at java.base/sun.security.ssl.SSLSocketInputRecord.handleUnknownRecord(SSLSocketInputRecord.java:442) ~[na:na]
        at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:175) ~[na:na]
        at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:110) ~[na:na]
        at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1475) ~[na:na]
        at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1381) ~[na:na]
        at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:441) ~[na:na]
        at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:412) ~[na:na]
        at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:602) ~[jakarta.mail-1.6.5.jar!/:1.6.5]
        at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:376) ~[jakarta.mail-1.6.5.jar!/:1.6.5]
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:214) ~[jakarta.mail-1.6.5.jar!/:1.6.5]
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2160) ~[jakarta.mail-1.6.5.jar!/:1.6.5]
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722) ~[jakarta.mail-1.6.5.jar!/:1.6.5]
        at javax.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.6.5.jar!/:1.6.5]

也许是他们服务器的 SSL 版本?

标签: javaspringspring-bootubuntuzentyal

解决方案


推荐阅读