Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import javax.mail.internet.MimeBodyPart
  2. import javax.mail.internet.MimeMultipart
  3. import com.atlassian.jira.component.ComponentAccessor
  4. import com.atlassian.jira.mail.Email
  5. import com.atlassian.mail.server.SMTPMailServer
  6.  
  7. @groovy.util.logging.Log4j
  8. class SendEmail
  9. {
  10. SMTPMailServer mailServer = null
  11.  
  12. SendEmail(mailServer = null)
  13. {
  14. if (mailServer == null) {
  15. this.mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
  16. }
  17. }
  18.  
  19. void send(String emailAddress, String subject, String body)
  20. {
  21. if (this.mailServer != null) {
  22. Email email = new Email(emailAddress)
  23.  
  24. MimeMultipart multipart = new MimeMultipart();
  25. MimeBodyPart mimeBodyPart = new MimeBodyPart()
  26.  
  27. mimeBodyPart.setContent(body, "text/html")
  28. multipart.addBodyPart(mimeBodyPart)
  29.  
  30. email.setSubject(subject)
  31. email.setBody(multipart.toString())
  32.  
  33. this.mailServer.send(email)
  34.  
  35. log.debug("Mail sent")
  36. } else {
  37. log.debug("Please make sure that a valid mailServer is configured")
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement