F
F
Fedor unknown2021-09-15 12:13:41
Java
Fedor unknown, 2021-09-15 12:13:41

Why is the email sending error?

When sending a message,
it throws an error:

javax.mail.AuthenticationFailedException: 535 Error: authentication failed


What could be the problem?

Code:
@RestController
@RequiredArgsConstructor
public class SendMail {

    private final JavaMailSender sender;

    @RequestMapping("/test")
    public String sendMail(){
        SimpleMailMessage mailMessage = new SimpleMailMessage();

        mailMessage.setFrom("massage");
        mailMessage.setTo("[email protected]");
        mailMessage.setSubject("Здравствуйте!");
        mailMessage.setText("Отправил");
        sender.send(mailMessage);

        return "Message send!";
    }
}


properties:
spring.mail.port = 465
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false
spring.mail.properties.mail.smtp.tsl.enable=true

spring.mail.host=smtp.163.com
spring.mail.username=*********
spring.mail.password=******
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor unknown, 2021-09-15
@turdubekov

Decided!
changed spring.mail.host=smtp.163.com to spring.mail.host=smtp.gmail.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question