So I am making a new API that sends UUIDs from the application through Email when you Sign-up.
@Service
public class MailSender {
@Autowired
private JavaMailSender sender;
public void sendEmail(String email, String subject, String body) {
try {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("[email protected]");
message.setTo(email);
message.setSubject(subject);
message.setText(body);
sender.send(message);
System.out.println("Mail sent to: " + email);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
}
@SpringApplication
@Controller
public class AnotherClass {
public void sendEmail(User user) {
try {
sender.sendEmail(user.getEmail(), "COINIFY ID", user.getId());
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
Getting a NullPointerException because JavaMailSender is null.
Can’t fix it for the life of me.
New contributor
METK4 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.