code_junkie

Grails Error for using e-mail service

Nov 13th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. JavaMailerService javamailerservice
  2. def x = {javamailerservice.serviceMethod()} }
  3.  
  4. boolean transactional = false
  5.  
  6. def serviceMethod() { String d_email = "[email protected]",
  7. d_password = "thispassword",
  8. d_host = "smtp.gmail.com",
  9. d_port = "587",
  10. m_subject = "Testing",
  11. m_text = "Hey, this is the testing email.";
  12.  
  13. Properties props = new Properties();
  14. props.put("mail.smtp.user", d_email);
  15. props.put("mail.smtp.host", d_host);
  16. props.put("mail.smtp.port", d_port);
  17. props.put("mail.smtp.starttls.enable","true");
  18.  
  19. SecurityManager security = System.getSecurityManager();
  20.  
  21. try
  22. {
  23. Authenticator auth = new SMTPAuthenticator();
  24. Session session = Session.getInstance(props, auth);
  25. //session.setDebug(true);
  26.  
  27. MimeMessage msg = new MimeMessage(session);
  28. msg.setText(m_text);
  29. msg.setSubject(m_subject);
  30. msg.setFrom(new InternetAddress(d_email));
  31. msg.addRecipient(Message.RecipientType.TO,
  32.  
  33. class JavaMailerController {
  34. JavaMailerService javaMailerService
  35. def x = {
  36. javaMailerService.serviceMethod()
  37. }
  38. }
Add Comment
Please, Sign In to add comment