Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Unable to send mail using Spring Framework

By sending an email I got the following exception:

org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. b10sm22671312wmi.34 - gsmtp

Here is the code that I'm using for sending email:

MailRequest mailRequest = new MailRequest();
mailRequest.setSubject(messageByLocale.getMessage("mail.subject.forgetpassword"));
mailRequest.setTemplateName(messageByLocale.getMessage("mail.template.forgetpassword"));
mailRequest.setToEmail(tbNstyleloyalty.getEmail());
Map<String, Object> map = new HashMap<>();
map.put("tbNstyleloyalty", tbNstyleloyalty);
mailingConfig.sendEmail(mailRequest, map);

And my sendEmail method is:

@Async
public void sendEmail(MailRequest mailRequest, Map<String, Object> model) {
    MimeMessagePreparator preparator = new MimeMessagePreparator() 
    {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setTo(mailRequest.getToEmail());
                message.setSubject(mailRequest.getSubject());
                message.setText(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,templatePath + mailRequest.getTemplateName() + ".vm", ApplicationConstants.CHARSET_UTF8, model),true);
         }
    };
    this.javaMailSender.send(preparator);
}

Please, help me to overcome from this issue.

Thank you!

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Thank you guys for your answers. All answers given by you were correct but I was unable to understand where I should add this property.

Finally I add:

spring.mail.properties.mail.smtp.starttls.enable = true

to my property file and then I got success.

about 4 years ago · Santiago Trujillo Relatório

0

Probably you are missing either of the 2 points:

  1. Set the following property in your email request.

props.put("mail.smtp.starttls.enable", "true");

  1. You are probably attempting to use mail server on port 25 to deliver mail to a third party over an unauthenticated connection.You will need to ask your SMTP client to connect to an authenticated connection. (look if your port number is for TLS connection)
about 4 years ago · Santiago Trujillo Relatório

0

I guess that your mail server uses STARTSSL for authentication (as the exception message implies).

Maybe this post helps: JavaMail smtp properties (for STARTTLS)

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda