Tag Archives: Mandrill

Back to blog home page

Deeper Mandrill integration using AWS Lambda

Posted by on Mar 21, 2017

Mandrill is a transactional email API built by MailChimp to facilitate programmatic communications with your app’s users. While we already have some demonstration JavaScript for sending a plain message via Mandrill, supporting attachments needs a server-side Node.JS Action. Below, we’ll create a server-side Node JS action (powered by AWS Lambda) that imports the Mandrill SDK, allowing you to easily send email with attachments through Mandrill in your Backand application.

Getting Started in Backand

To get started with a Mandrill action, you’ll need to first create a new Server-Side NodeJS action in Backand. To do so, open up your app’s dashboard at https://www.backand.com, and navigate to an object that will host the action. On the Actions tab of this object, create a new “On Demand” action. Name this action, then select “Server-Side Node.JS Action” as the action’s type. Follow the documentation provided to download the Backand CLI and initialize your action locally.

Backand’s Server-Side Node.js actions are implemented as Amazon Lambda functions. These functions are built using Node.js, and deployed as you would any other Node application. Backand provides a convenient CLI for managing these actions (documented in the action description), as well as easy-to-use tools to trigger execution of the Lambda function from the REST API.

Initializing the Mandrill Action

Once you have the Server-Side Node.js action ready to go, the next step is to create an action in Mandrill. Navigate to http://www.mandrill.com/ and create a new action in the MailChimp dashboard provided when you log in. Once the action is ready, copy down the Mandrill API Key value and save it somewhere safe. This API key will be used by the Node.js action to connect and communicate with Mandrill.

Updating the Code

Next, we’ll need to update the action’s code to communicate with Mandrill. We’ll start by configuring the mandrill SDK requirements in index.js. Add these lines into index.js in your Node.js action folder structure, before the function exports.backandCallback:

Note: Be sure to replace MANDRILL_API_KEY with the value copied down from the Mandrill dashboard.

Next, we’ll modify the backandCallback function to send a message with Mandrill. Replace the contents of this function with the following code:

This code does two things:

The initial code fetches the attachment data from the server on which it is stored. If this code succeeds, it calls sendEmail with the file data provided as a Base 64 string.
sendEmail then takes this data and contacts Mandrill to send the message.

Configuring the Code

To tie the project together and finalize the above code, simply replace each of the placeholders with the appropriate value:

  • PATH_TO_ATTACHMENT_INCLUDING_FILENAME – this is the URL to the attachment you wish to send. If fetching this fails, sending the message will not succeed.
  • FILENAME_OF_ATTACHMENT – this is the file name that will be given to the attachment.
  • RECIPIENT_EMAIL – This is the email for the message’s intended recipient.
  • RECIPIENT_DISPLAY_NAME – This is the recipient’s display name.
  • SENDER – This is the email from which the message was sent.
  • EMAIL_SUBJECT – This is the subject of the email.
  • MESSAGE_BODY – This is the content of the email.

You can also use the parameters argument to the action to send additional message data, whether that data originates in your app’s database or via the API call. Once these changes are made, your server-side action is ready to deploy!

Testing and Deployment

You can debug and run the action locally using the provided debug.js file. Simply enter node debug.js on the command line to debug. Once you’ve finished your local testing, you can then deploy the action via the documentation provided in the Server-Side Action’s UI in your app’s dashboard at Backand.com – head to the Actions tab for the relevant object, and follow the instructions on using backand action deploy to deploy your code.

Calling the Action

To call the action in your client-side code, simply use the Backand SDK’s action functionality as you would any other on-demand action:

Simply replace OBJECT_NAME with the name of the object controlling your action, and ACTION_NAME with the Server-Side Node.js Action’s name in Backand. You can provide any extra information or detail using the provided parameters object – this will be passed into the parameters argument of your action.

Conclusion

Many apps need to send additional supporting documents along with their transactional messages, such as images used in the message or related files. With the above Server-Side Node.js Action, you’re given the full capability necessary to enhance your transactional messages with any attachments you see fit. Learn more about Backand’s Server-Side Node.js actions in the documentation, or make use of our previous example on sending messages without an attachment from a custom JavaScript action.

Back to blog home page

Deep Dive Series: Integrating Backand with Ionic Creator, Mandrill & More

Posted by on Mar 14, 2017

Over the next several days, we’ll be running a set of deep-dive blog posts. Each post will cover a different topic in-depth, providing a deeper look at integrating Backand into a number of different application development scenarios. The posts will cover three differing topics, showing a range of functionality that can be implemented into a serverless app. A brief overview of each topic is provided below, to serve as a reading guide.

Integrating Backand with Ionic Creator

Ionic Creator is a powerful online development environment for Ionic apps. While it provides a convenient, UI-focused means for implementing a multi-platform application, it can make some tasks – such as integrating with a third-party service provider like Backand – challenging. In the article on integrating with Ionic Creator, we’ll cover the steps necessary to get Ionic Creator working with our new SDK. By following the steps in this article, you’ll be able to make your apps truly portable through the use of our serverless platform and Ionic’s core offering of cross-platform capable and consistent user interfaces.
Read more

Sending Email Attachments with Mandrill

While we can easily send email messages over MailChimp’s Mandrill API with simple HTTP calls, any message that includes an attachment needs to be created on the server side. In the Mandrill Attachments article, we’ll cover the process for creating a Node.JS Server-Side JavaScript action that can add an attachment to a transactional email sent via Mandrill. We’ll cover the JavaScript code you need to fetch a file from the web, convert it to a format Mandrill can accept, and then initiate the message send.
Read more

Batch and Bulk Processing in Backand

Backand’s automated REST API generation provides developers with a significant amount of functionality right off the bat, allowing your app to quickly begin working with the objects represented in your application’s database. However, these APIs are limited to working with a single record or retrieving a list of records. If you wish to create multiple records at once or update several objects across multiple database tables in a single API call, then you’ll want to make use of our bulk processing API. We’ll provide all of the details you need to create bulk processing requests, allowing you to easily update large numbers of records in your application’s Backand database.
Read more

Other topics

We’re always looking to help developers understand how to better work with the Backand platform. Our goal is to make developing your app easier, and we’d love to hear from you if you have an idea that would help us achieve that goal. Simply contact us via social media, or using our contact form to start a conversation!