1. Introduction

The Mail plugin adds the ability to send email from your Griffon application.

Griffon version: 2.12.0

2. Usage

The following sections describe how you may use this plugin in a project.

2.1. Configuration

The plugin’s module registers a MailHandler helper class that defines the base contract for sending messages using the Java Mail API.

griffon.plugins.mail.MailHandler.java
void sendMail(@Nonnull MailOptions options);

The endMail blocks until the mail is sent or until the request times out. You are responsible for making sure it is called off of the UI thread so it doesn’t affect your application if the SMTP server is not available.

The following options may be defined:

Property Type Required Notes

transport

Transport

no

either SMTP or SMTPS. Defaults to SMTP

host

String

yes

the address of the SMTP server, e.g. 'smtp.google.com'

port

String

no

the port of the SMTP server. Defaults appropriately for the transport specified

auth

boolean

no

true if authentication is required, false otherwise. Defaults to false

user

String

no

the username for authenticating with the SMTP server. Only used if auth=true

password

String

no

the password for authenticating with the SMTP server. Only used if auth=true

from

String

no

the message sender, e.g. 'foo@bar.com'

to

String

yes

the message recipient(s), e.g. 'foo@bar.com'. Multiple addresses may be specified as a comma-separated list, e.g. 'foo@bar.com, bar@bar.com'

cc

String

no

the CC recipients(s), e.g. 'foo@bar.com'. Multiple addresses may be specified as a comma-separated list, e.g. 'foo@bar.com, bar@bar.com'

bcc

String

no

the BCC recipients(s), e.g. 'foo@bar.com'. Multiple addresses may be specified as a comma-separated list, e.g. 'foo@bar.com, bar@bar.com'

subject

String

no

the message subject.

mimeType

MimeType

no

the message’s mime-type. Default is TEXT

attachments

List<String>

no

the list of file paths (as Strings) to attach to the email

props

Map<String,Object>

no

additional properties

You can inject an instance of MailHandler anywhere it’s needed using @Inject.

2.2. Defaults

With the exception of to, all parameters may be defined in the application’s configuration file, using mail as a prefix. For example here is how you would configure the default sender to send with a Gmail account:

griffon-app/conf/Config.groovy
mail {
    host     = 'smtp.gmail.com'
    port     = 465
    username = 'youraccount@gmail.com'
    password = 'yourpassword'
    props = [
        'mail.smtp.auth': 'true',
        'mail.smtp.socketFactory.port': '465',
        'mail.smtp.socketFactory.class': 'javax.net.ssl.SSLSocketFactory',
        'mail.smtp.socketFactory.fallback': 'false'
    ]
}

3. Configuration

3.1. Gradle

You have two options for configuring this plugin: automatic and manual.

3.1.1. Automatic

As long as the project has the org.codehaus.griffon.griffon plugin applied to it you may include the following snippet in build.gradle

dependencies {
    griffon 'org.codehaus.griffon.plugins:griffon-mail-plugin:1.0.0'
}

The griffon plugin will take care of the rest given its configuration.

3.1.2. Manual

You will need to configure any of the following blocks depending on your setup

dependencies {
    compile 'org.codehaus.griffon.plugins:griffon-mail-core:1.0.0'
}

3.2. Maven

First configure the griffon-mail-plugin BOM in your POM file, by placing the following snippet before the <build> element

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.griffon.plugins</groupId>
            <artifactId>griffon-mail-plugin</artifactId>
            <version>1.0.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Next configure dependencies as required by your particular setup

<dependency>
    <groupId>org.codehaus.griffon.plugins</groupId>
    <artifactId>griffon-mail-core</artifactId>
</dependency>

4. Modules

The following sections display all bindings per module. Use this information to successfully override a binding on your own modules or to troubleshoot a module binding if the wrong type has been applied by the Griffon runtime.

4.1. Mail

Module name: mail

bind(MailHandler.class)
    .to(DefaultMailHandler.class)
    .asSingleton();