Greenmail Plugin for Grails
Dependency :
compile ":greenmail:1.3.4"Custom repositories :
mavenRepo "http://download.java.net/maven/2/"
Summary
Provides a wrapper around GreenMail (http://www.icegreen.com/greenmail/) and provides a view that displays 'sent' messages
Description
Greenmail Plugin
Provides a wrapper around GreenMail and provides a view that displays 'sent' messages - useful for testing application in the 'development' or 'test' environments.Please create issues in JIRA if you encounter problems.
Installation
grails install-plugin greenmail
environments {
production {
grails.serverURL = "http://www.changeme.com"
}
development {
grails.mail.port = com.icegreen.greenmail.util.ServerSetupTest.SMTP.port
grails.serverURL = "http://localhost:8080/${appName}"
}
test {
grails.mail.port = com.icegreen.greenmail.util.ServerSetupTest.SMTP.port
grails.serverURL = "http://localhost:8080/${appName}"
}
}environments {
production {
greenmail.disabled=true
}
}Usage in Integration Tests
The plugin can be used to capture email messages during integration tests. For example:import com.icegreen.greenmail.util.*class GreenmailTests extends GroovyTestCase { def mailService def greenMail void testSendMail() { Map mail = [message:'hello world', from:'from@piragua.com', to:'to@piragua.com', subject:'subject'] mailService.sendMail { to mail.to from mail.from subject mail.subject body mail.message } assertEquals(1, greenMail.getReceivedMessages().length) def message = greenMail.getReceivedMessages()[0] assertEquals(mail.message, GreenMailUtil.getBody(message)) assertEquals(mail.from, GreenMailUtil.getAddressList(message.from)) assertEquals(mail.subject, message.subject) } void tearDown() { greenMail.deleteAllMessages() } }
deleteAllMessages() convenience method to the greenMail bean that deletes all received messages.Usage in running application
The plugin provides a controller and view to show messages that are 'sent' from the application. Simply browse to http://localhost:8080/<YOUR_APP>/greenmail and it will show a list of messages sent. You can click on the "show" link to view the raw message.Email List screen:
Raw Message example:
Roadmap:
This is a fully functional plugin, though there are some features that I think would be worth adding. Contributions and patches are welcome! Create a JIRA ticket with a patch or request plugin developer access and make the change directly in the SVN plugin repository (an email to the author is appreciated)
- Messages sent by the Grails Mail plugin have duplicate "TO:" fields in the raw message and in the address list, for instance if the recipient is spam@piragua.com, then that email address is listed twice when you retrieve the address list for RecipientType.TO (e.g. GreenMailUtil.getAddressList(message.getRecipients(javax.mail.Message.RecipientType.TO))
- Ability to view HTML email messages as they appear in a mail client rather than as RAW message.