Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WebConfig {
- @Bean(name="mailSender")
- public MailSender javaMailService() {
- JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
- javaMailSender.setHost("smtp.gmail.com");
- javaMailSender.setPort(587);
- javaMailSender.setProtocol("smtp");
- javaMailSender.setUsername("email@gmail.com");
- javaMailSender.setPassword("password");
- Properties mailProperties = new Properties();
- mailProperties.put("mail.smtp.auth", "true");
- mailProperties.put("mail.smtp.starttls.enable", "starttls");
- mailProperties.put("mail.smtp.debug", "true");
- javaMailSender.setJavaMailProperties(mailProperties);
- return javaMailSender;
- }
- }
- @RestController
- public class SendMailController {
- @Autowired
- MailService mailservice ;
- @Autowired
- private JavaMailSender mailSender;
- private Mail mail ;
- @RequestMapping( value="/sendMail/", method =RequestMethod.POST, produces="application/json", consumes="application/json")
- public void emailTest(){
- SimpleMailMessage smm = new SimpleMailMessage();
- smm.setFrom("email@gmail.com");
- smm.setTo("email@gmail.com");
- smm.setSubject("title");
- smm.setText("text");
- mailSender.send(smm);
- }
- }
Add Comment
Please, Sign In to add comment