Error sending email using Javamailsender - Microsoft Exchange 10

Asked

Viewed 50 times

0

Good morning!

I cannot send the email. All the settings I tried to use return the same error:

WARN  o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolved [org.springframework.web.server.ResponseStatusException: 400 BAD_REQUEST "Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: exchange-ipa.dominio.su.net, 25; timeout -1;
java.net.ConnectException: Connection timed out: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: exchange-ipa.dominio.su.net, 25; timeout -1;

I am using Spring boot - Javamailsender, according to the code below.

With another email that we have here at the company, send without problems.

Can help me?

Thank you in advance.

Follow the email configs:

Caixa Postal SMTP: [email protected]
Domínio\Usuário: Dominio\UJDLKSHFDUH012
Senha: Psjkj1#48K
Host: exchange-ipa.dominio.su.net
Porta: 25 (tentei com a 587 também)

Follow the source:

static final String dsEmail = "Dominio\\UJDLKSHFDUH012";
static final String dsSenha = "Psjkj1#48K";
    
public void enviarEmail(String login, String email, String token, String mensagem, String assunto) throws MailException, MessagingException {

        Global.getSetTokenConfirmaEmail(email.toLowerCase(), token, true, false);
        
        JavaMailSender emailSender = mailSender();
        MimeMessage message = emailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        
        helper.setTo(email.toLowerCase());
        helper.setSubject(assunto);
        helper.setFrom("[email protected]");
        helper.setSentDate(new Date());
        helper.setText(mensagem, true);
        
        try {

            emailSender.send(message);

     } catch (Exception e) {

            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
     }
    }
    
    public JavaMailSender mailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        
        mailSender.setHost("exchange-ipa.dominio.su.net");
        mailSender.setPort(25);
        
        mailSender.setDefaultEncoding("UTF-8");
        
        mailSender.setUsername(dsUsuario);
        mailSender.setPassword(dsSenha);

        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.smtp.connectiontimeout", true);
        
         mailSender.setJavaMailProperties(props);

        return mailSender;
    }

1 answer

0

Is working.

I’m not sure if the problem was in this configuration :

props.put("mail.smtp.starttls.enable", true); //alterei para false

or if the team that manages the servers has changed something there for the release, anyway, the code above works.

Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.