Revolution11 has had great success incorporating Mandrill, a scalable, secure delivery API for sending transactional emails from websites and applications for clients who need to send email from their FileMaker solution. Mandrill is easy to get to know and once established, works well for targeted e-commerce and personalized one-to-one messages. For our discussion we will explain how the Mandrill Sample File constructs the URL to send to the Mandrill API, which then sends the email.
The benefits of sending email via Mandrill can be seen here: Mandrill Features. We were impressed with the simplicity of the process, but wanted to also add attachments to the emails to cover the many times that would come in handy from a business standpoint.
The screenshot shows the basic email form – the user creates a free account at Mandrill, subscribes to a paid MailChimp account (a fairly recent requirement), then uses the Mandrill Sample File to fill out the To/From information and message (seen on the left) and easily add an attachment, if needed. The right side shows the visual output of the custom functions and calculations that are generated at Mandrill.
This blog post from Digital Fusion gives great information on how to construct this file: Sending email from FileMaker using Mandrill. Now, on to the fun stuff with the custom functions needed to add the attachments…
Custom Function: mandrill_createRequestInsertURL
File > Manage > Custom Functions > Edit (to see it).
This function takes in all the parameters (Example: To, From, Subject, API key, etc.) and creates the URL Request.
This function also uses a helper function called escapeData that handles any special characters in the email address, subject, etc. (Example: &, %, `, etc.)
Custom Function: mandrill_attachmentCodeInsert
This function helps handle attaching the file to the email. Read more about the gritty details here: Sending email from FileMaker using Mandrill
Now that we’ve used our custom function to create our URL request, it’s time to create the “InsertURL Template.” This is a calculated field that we use to finalize our URL request to the Mandrill API.
File > Manage > Database > Select the “Insert From URL Template” > click on Options (lower right)
As you can see once you’re viewing the calculated field, this uses the mandrill_createRequestInsertURL custom function and creates the URL we send to Mandrill.
To sum up, this is the structure of the URL used to build this function. Inputs from these two field ultimately create the URL to be used.
URL to Mandrill API / Insert From URL Results
URL to Mandrill API is always the same and should be pre-filled into the corresponding field. Insert From URL Results is the result of the custom function, mandrill_createRequestInsertURL and is ultimately a calculated field.
Now that we have our URL, the hard part is done and we just need a simple script to send the email.
Now that we have our URL constructed, the sendEmail script is a simple process. The meat and potatoes of this script is FileMaker’s “Insert from URL” function. We just pass in two fields that create this URL. We pass in the “URL to API” which is a constant, and add our calculated “Insert From URL Results” field to the end of the URL, and we’re good to go.
Attach this script to the “Send Email” button and you’re done! We would love to get your feedback on this script and learn how it has worked for you.
Get a PDF of this blog here: FileMaker Mandrill Integration