////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

Message content is specified by either the `text` and/or `html` methods that specify the plain-text or HTML content respectively.

==== HTML Email

To send HTML email you can use the `html` method. This will set the content type of the message to `text/html`.

You can either supply a string value:

[source,groovy]
----
sendMail {
    to 'user@somewhere.org'
    subject 'Hello John'
    html '<b>Hello</b> World'
}
----

Or a view to render to form the content:

[source,groovy]
----
sendMail {
    to 'user@somewhere.org'
    subject 'Hello John'
    html view: '/emails/hello', model: [param1: 'value1', param2: 'value2']
}
----

See the section on using views for more details of the parameters to this version of `html`.

==== Text Email (plain-text)

To send plain-text email you can use the `text` method. This will set the content type of the message to `text/plain`.

You can either supply a String value:

[source,groovy]
----
sendMail {
    to 'user@somewhere.org'
    subject 'Hello John'
    text 'Hello World'
}
----

Or a view to render to form the content:

[source,groovy]
----
sendMail {
    to 'user@somewhere.org'
    subject 'Hello John'
    text view: '/emails/hello', model: [param1: 'value1', param2: 'value2']
}
----

See the section on using views for more details of the parameters to this version of `text`.

==== Text and HTML

It is possible to send a multipart message that contains both plain-text and HTML versions of the message. In this situation, the email-reading client is responsible for selecting the variant to display to the user.

To do this, simply use both the `html` and `text` methods:

[source,groovy]
----
sendMail {
    to 'user@somewhere.org'
    subject 'Hello John'
    text view: '/emails/text-hello', model: [param1: 'value1', param2: 'value2']
    html view: '/emails/html-hello', model: [param1: 'value1', param2: 'value2']
}
----

==== Using Views

Both the `text` and `html` methods support specifying a view to render to form the content. These are the accepted parameters:

* The _view_ is the absolute path (or relative to the current controller if during a request) to the GSP, just like the existing Grails `render` method.
* The _plugin_ parameter is only necessary if the view you wish to render comes from a plugin, just like the existing Grails `render` method.
* The _model_ parameter is a map representing the model the GSP will see for rendering data, just like the existing Grails `render` method.
