Send email using Microsoft SMTP server in Spring Boot

Viewed 269

I do want to send email from my SMTP server using spring boot app. But I am getting errors. Here's my below code:

Note: I dont require username and password to use SMTP server.

application.properties

spring.mail.host=1.1.1.1
spring.mail.port=25

sender class:

    @Autowired
    private JavaMailSender javaMailSender;


  String constRecipient = "test@gmail.com";
  String sender = "sss@domain.com";
  String subject = "Test";
  String password = "aaa";


  sendEmail(constRecipient, sender, subject, newPassword);


//my method
  void sendEmail(String recipient, String sender, String subject, String password) {
        SimpleMailMessage msg = new SimpleMailMessage();
        msg.setFrom(sender);
        msg.setTo(recipient);
        msg.setSubject(subject);
        msg.setText("Hi, \n Your new password is " + password + "\nThanks.");

        javaMailSender.send(msg);

    }

I am getting this error:

Authentication failed; nested exception is javax.mail.AuthenticationFailedException: failed to connect, no password specified?

1 Answers

Try This:

this.javaMailSender.send(msg);
Related