Guest User

Untitled

a guest
Aug 10th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public class WebConfig {
  2.  
  3. @Bean(name="mailSender")
  4. public MailSender javaMailService() {
  5. JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
  6. javaMailSender.setHost("smtp.gmail.com");
  7. javaMailSender.setPort(587);
  8. javaMailSender.setProtocol("smtp");
  9. javaMailSender.setUsername("email@gmail.com");
  10. javaMailSender.setPassword("password");
  11. Properties mailProperties = new Properties();
  12. mailProperties.put("mail.smtp.auth", "true");
  13. mailProperties.put("mail.smtp.starttls.enable", "starttls");
  14. mailProperties.put("mail.smtp.debug", "true");
  15. javaMailSender.setJavaMailProperties(mailProperties);
  16. return javaMailSender;
  17. }
  18.  
  19. }
  20.  
  21. @RestController
  22. public class SendMailController {
  23.  
  24. @Autowired
  25. MailService mailservice ;
  26. @Autowired
  27. private JavaMailSender mailSender;
  28.  
  29.  
  30. private Mail mail ;
  31.  
  32. @RequestMapping( value="/sendMail/", method =RequestMethod.POST, produces="application/json", consumes="application/json")
  33.  
  34. public void emailTest(){
  35.  
  36. SimpleMailMessage smm = new SimpleMailMessage();
  37.  
  38. smm.setFrom("email@gmail.com");
  39. smm.setTo("email@gmail.com");
  40. smm.setSubject("title");
  41. smm.setText("text");
  42.  
  43. mailSender.send(smm);
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment