Last change
on this file since 58 was
58,
checked in by gav, 15 years ago
|
Configure BootStrap? with latest concepts.
Install and setup Acegi plugin with custom views.
Test Fixture plugin in a test app but couldn't get it to work with Acegi encodePassword() so gave up.
|
File size:
1.2 KB
|
Rev | Line | |
---|
[58] | 1 | import javax.mail.MessagingException |
---|
| 2 | |
---|
| 3 | import org.springframework.mail.MailException |
---|
| 4 | import org.springframework.mail.SimpleMailMessage |
---|
| 5 | |
---|
| 6 | /** |
---|
| 7 | * Simple service for sending emails. |
---|
| 8 | * |
---|
| 9 | * Work is planned in the Grails roadmap to implement first-class email |
---|
| 10 | * support, so there's no point in making this code any more sophisticated. |
---|
| 11 | * |
---|
| 12 | * @author Haotian Sun |
---|
| 13 | */ |
---|
| 14 | class EmailerService { |
---|
| 15 | |
---|
| 16 | boolean transactional = false |
---|
| 17 | |
---|
| 18 | def mailSender |
---|
| 19 | def mailMessage // a "prototype" email instance |
---|
| 20 | |
---|
| 21 | /** |
---|
| 22 | * Send a list of emails. |
---|
| 23 | * |
---|
| 24 | * @param mails a list of maps |
---|
| 25 | */ |
---|
| 26 | def sendEmails(mails) { |
---|
| 27 | |
---|
| 28 | // Build the mail messages |
---|
| 29 | def messages = [] |
---|
| 30 | for (mail in mails) { |
---|
| 31 | // create a copy of the default message |
---|
| 32 | def message = new SimpleMailMessage(mailMessage) |
---|
| 33 | message.to = mail.to |
---|
| 34 | message.text = mail.text |
---|
| 35 | message.subject = mail.subject |
---|
| 36 | messages << message |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | // Send them all together |
---|
| 40 | try { |
---|
| 41 | mailSender.send(messages as SimpleMailMessage[]) |
---|
| 42 | } |
---|
| 43 | catch (MailException e) { |
---|
| 44 | log.error "Failed to send emails: $e.message", e |
---|
| 45 | } |
---|
| 46 | catch (MessagingException e) { |
---|
| 47 | log.error "Failed to send emails: $e.message", e |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.