0

Well, I'm trying to deploy an API service with spring boot. The problem came when I started using their mail server (Zentyal postfix mail server) for production settings. A system is a Virtual machine with an API service that needs to send emails from the parent server. I try many things in the documentation of email, but nothing works (Gmail settings for dev works fine).

My application.properties is this

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

This is my method.

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

So, Gmail as I said works fine, the deal is the email message sending is correct in spring, all messages sended. The problem starts with the mail server. This a pic of the log when I send a mail.

enter image description here

The only I know from the email server is a Zentyal server and is using postfix, i'm configuring blinded right now because they're jelous with their information. They give me a python code that works and send emails, but spring boot isn't, if any of you have a possible solution I'll be grateful.

Edit:

I tested again and now the logs send me this:

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]

Maybe the SSL version from their server?

João Dias
  • 16,277
  • 6
  • 33
  • 45
drkpkg
  • 73
  • 1
  • 1
  • 10

0 Answers0