I am working on sending the email via smtp.gmail in Spring boot.
EmailConfig.java
@Configuration
public class EmailConfig
{
@Bean
public JavaMailSender getJavaMailSender()
{
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(25);
mailSender.setUsername("[email protected]");
mailSender.setPassword("123");
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
return mailSender;
}
@Bean
public SimpleMailMessage emailTemplate()
{
SimpleMailMessage message = new SimpleMailMessage();
message.setTo("[email protected]");
message.setFrom("[email protected]");
message.setText("FATAL - Application crash. Save your job !!");
return message;
}
}
SendEmailService.java
@Service("emailService")
public class SendEmailService {
@Autowired
JavaMailSender mailSender;
@Autowired
private SimpleMailMessage preConfiguredMessage;
public void sendPreConfiguredMail(String message)
{
SimpleMailMessage mailMessage = new SimpleMailMessage(preConfiguredMessage);
mailMessage.setText(message);
mailSender.send(mailMessage);
}
}
Error : I have received an email on my account "Sign-in attempt was blocked" Someone just used your password to try to sign in to your account from a non-Google app. Google blocked them, but you should check what happened. Review your account activity to make sure no one else has access
How to figure out this.
just go to your account security and allow less secure apps to "ON"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With