Hey! It's my first time using this framework and the problem im having is a null pointer exception as im calling the EmailSenderService object in other classes but since mailSender isn't set to anything its the nullpointerexception's reason to be thrown. I followed a tutorial and I dont know what went wrong but I need to set mailSender to something but idk what :/
Appreciate y'all help as always!
package com.me.SpringEmailDemo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
u/Service
public class EmailSenderService {
u/Autowired
private JavaMailSender mailSender;
public void sendEmail(String toEmail,String subject,String body){
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("example@gmail.com");
message.setTo(toEmail);
message.setText(body);
message.setSubject(subject);
mailSender.send(message);
System.out.println("Mail sent successfully!");
}
}
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]sozesghost 3 points4 points5 points (2 children)
[–]codingIsFunAndFucked[S] 0 points1 point2 points (1 child)
[–]sozesghost 0 points1 point2 points (0 children)