1. Introduction
GR8 CRM is a set of Grails Web Application Framework plugins that makes it easy to develop web applications with CRM functionality.
You can find more information about GR8 CRM on the main documentation site http://gr8crm.github.io.
1.1. Customer relationship management
Customer relationship management (CRM) is a system for managing a company’s interactions with current and future customers. It involves using technology to organize, automate and synchronize sales, marketing, customer service, and technical support. Wikipedia
The GR8 CRM "Ecosystem" currently contains over 40 Grails plugins. For a complete list of plugins see http://gr8crm.github.io.
Each GR8 CRM plugin defines a Bounded Context that focus on one specific domain, for example contact, project or document.
2. Email Composition Plugin
This GR8 CRM plugin provides services, controllers and views for composing and sending emails in a GR8 CRM application. The email composition screen can display a list of FreeMarker templates that can be selected to quickly compose standard emails. Attachments are also supported, both uploaded local files and files stored in the application by the crm-content plugin.
3. CrmEmailService
3.1. Send email
String prepareForSendMail(HttpServletRequest request, Map params)
To send an email with the crm-email plugin you create a send configuration and pass it to the mail composition page. The composition page uses the configuration to initialize fields, templates and attachments.
def sendmail(Long id) {
def contact = crmContactService.getContact(id) (1)
def user = crmSecurityService.getUserInfo() (2)
def token = crmEmailService.prepareForSendMail(request, [
tenant : TenantUtils.tenant,
user : user,
referer: createLink(action: "show", id: id),
senders: ["${user.name} <${user.email}>", "My Company Inc. <info@mycompany.com>"],
from : "${user.name} <${user.email}>",
to : "${contact.name} <${contact.email}>",
subject: "Order Confirmation",
body : "Hi $contact, I'm pleased to let you know that your order has been confirmed."
]) (3)
redirect mapping: 'crm-mail-send', id: token (4)
}
1 | In this example we lookup a customer (contact) that we want to send email to |
2 | The current user will be the sender |
3 | This creates an email configuration that is stored in the user’s session |
4 | Redirect to the generic sendmail page, there the user can finish the message and send it |
3.1.1. Multiple recipients
The above code example opens the email composition screen and send the email to one recipient. Combined with the selection plugin we can compose an email the same way and send to a group of recipients.
It works like this: The user searches for a group of recipients using a standard query form. When the result page is displayed with the matching list of recipients, the user clicks a button to invoke the email composition screen to send to the group.
You must have a controller action that prepares a send configuration then redirects to the email composition screen.
You store the last executed query (encoded as a URI) in the send configuration (key=selection).
The query will be re-executed by CrmEmailService
and each recipient will receive an individual copy of the email.
def sendmail() {
def selection = params.getSelectionURI() (1)
def user = crmSecurityService.getUserInfo() (2)
def token = crmEmailService.prepareForSendMail(request, [
tenant : TenantUtils.tenant,
user : user,
referer : createLink(action: "index"),
senders : ["${user.name} <${user.email}>", "My Company Inc. <info@mycompany.com>"],
from : "${user.name} <${user.email}>",
selection: selection,
subject : "GR8 CRM News",
html : '<p>Hi ${m.firstName}, I'm pleased to let you know that the crm-email plugin now can send to a group of recipients.</p>'
+ '<p><img src="cid:logo" alt="Logo"/></p>',
inline : [[name: 'logo', contentType: 'image/png', withInputStream: { it(logoResource.getInputStream()) }]]
]) (3)
redirect mapping: 'crm-mail-send', id: token (4)
}
1 | When using the selection plugin we can get the last executed query encoded as a URI |
2 | The current user will be the sender |
3 | This creates an email configuration that is stored in the user’s session |
4 | Redirect to the generic sendmail page, there the user can finish the message and send it to all people in the collection/selection |
4. Changes
- 2.4.1
-
Added support for replyTo: and inline images
- 2.4.0
-
First version compatible with Grails 2.4.4
- 2.0.1
-
Added support for sending to multiple recipients using the
selection
plugin. - 2.0.0
-
First public release
5. License
This plugin is licensed with Apache License version 2.0
6. Source Code
The source code for this plugin is available at https://github.com/technipelago/grails-crm-email
7. Contributing
Please report issues or suggestions.
Want to improve the plugin: Fork the repository and send a pull request.