Reputation: 707
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.
Upvotes: 7
Views: 4638
Reputation: 522
Google changed some ways to do this, so now you can add a "special" password for your app.
On this page, you can create a unique pass, which needs used for login into your acc via an application.
Upvotes: 0
Reputation: 1357
Upvotes: 17
Reputation: 73
just go to your account security and allow less secure apps to "ON"
Upvotes: 2