Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda