Code Monkey home page Code Monkey logo

greenmail's Introduction

Greenmail Plugin for Grails 3

This is a fork of grails greenmail plugin for grails 3.

INSTALL

Add a dependency for the plugin in build.gradle:


dependencies {    
    compile 'org.grails.plugins:greenmail:2.0.0.RC2'    
}

USAGE

Provides a wrapper around GreenMail and provides a view that displays sent messages - useful for testing application in the development or test environments.

Installation

grails install-plugin greenmail

The plugin assumes that you have some sort of Java mail provider installed (for instance the Grails mail plugin). You need to define a SMTP port for the mock Greenmail SMTP server to start with. Using the Grails Mail plugin, this is as simple as defining the grails.mail.port property in Config.groovy, like this (see the first line in the development and test blocks):

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}"
    }
}

You can also completely disable the plugin by using the config setting grails.plugin.greenmail.disabled = true. For example, to disable greenmail in production:

environments {
    production {
       grails.plugin.greenmail.disabled=true
    }
}

If you need to change the default listening port (1025) you can use the grails.plugin.greenmail.ports.smtp configuration variable. For example:

environments {
    test {
       grails.plugin.greenmail.ports.smtp = 2025
    }
}

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:'[email protected]', to:'[email protected]', 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()
    }
}

The plugin adds a 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/greenmail and it will show a list of messages sent. You can click on the show link to view the raw message.

Roadmap

This is a fully functional plugin, though there are some features that I think would be worth adding. Contributions and patches are welcome!

  • 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 [email protected], 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.

greenmail's People

Contributors

ldaley avatar mjhugo avatar sbglasius avatar antonevane avatar graemerocher avatar zacharyklein avatar kwongpan avatar bluesliverx avatar zyro23 avatar alvarosanchez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.