Send a file from Dropbox as an email attachment

Introduction

In this tutorial, you’ll learn how to create a pipe that regularly sends an email with an attachment from a file on Dropbox. This is useful if you want to send out a regular report or update to people based on a file in Dropbox without needing to share that file directly with the recipients of the email.

You’ll learn how to:

  • Connect to Dropbox
  • Create an email that attaches a file from Dropbox
  • Send the email from an API call
  • Send the email on a schedule

Setup

To complete this tutorial, you’ll need the following:

  • A Flex.io API key
  • A Dropbox account
  • A file on Dropbox that you’d like to send as an email attachment
  • An email address you’d like to send the email to

To get a Flex.io API key, sign up for Flex.io, or if you already have an account, sign in. When you sign in, you’ll see your API listed in the “API Keys” section on the dashboard where you’re directed after you sign in.

You’ll also need a Dropbox account with the file you want to email.

Finally, if you’d like to trigger the email with an API call, you’ll need a tool that allows you to make HTTP requests. We’ll show you how using CURL. If you’re simply scheduling the pipe to send the email on a regular basis, the Flex.io web application will allow you to set up the schedule to run the pipe.

Build it

Next, you’re ready to build the pipe to send the email. Following are the steps to build it manually; alternatively you can use this template to create the pipe for you.

When you’re done, you’ll have a pipe defined in the Flex.io webservice that looks like:

Create the connection

  1. Sign in to Flex.io.
  2. Open the Connections list by selecting “Connections” from the nav menu.
  3. In the Connections list, create a new connection by clicking the “New Connection” button.
  4. In the “New Connection” dialog, select Dropbox.
  5. Authenticate the connection by signing in to Dropbox.
  6. On the connection configuration screen, name your connection “Dropbox” and give your connection the alias “dropbox-connection” on the connection configuration screen.
  7. Save the connection.

Create the pipe

  1. Open the Pipes list by selecting “Pipes” from the nav menu.
  2. In the Pipes list, create a new pipe by clicking the “New Pipe” button.
  3. In the pipe properties section, name your pipe “Send Dropbox File as Email Attachment” and give your pipe an alias “send-dropbox-file-as-email-attachment”.
  4. In the pipe configuration section, add the following code to access your file on Dropbox and email it.
  5. Replace {email-address} with the email address of the person you’d like to send the file to; for testing the pipe, we recommend you email yourself the file initially.
  6. Replace {dropbox-path-to-file} with the name of the file you would like to email (for example “/source/my-folder/contacts.csv”):

Run the pipe

  1. In the pipe configuration section, click the “Run” button.
  2. The pipe should take about a second or so to run, and then you should get an email with the file from Dropbox.

Deployment

Once you’ve built the pipe, you’re ready to use it:

  1. You can send the email by invoking the API endpoint.

Go to your command prompt and run the following CURL command with the ‘send-dropbox-file-as-email-attachment’ alias you gave to the pipe:

curl -X POST 'https://api.flex.io/v1/me/pipes/send-dropbox-file-as-email-attachment/run'
--header "Authorization: Bearer {token}"
'

You should receive an email with the Dropbox attachment. In general, you can call pipes with an alias of your choice by filling in {pipe-alias} in the following:

curl -X POST 'https://api.flex.io/v1/me/pipes/{pipe-alias}/run'
--header "Authorization: Bearer {token}"
'
  1. You can also send the email on a regbular basis by scheduling the pipe to run with the scheduler.

To schedule a pipe:

  1. Sign in to Flex.io.
  2. Select Pipes from the menu to see a list of your pipes.
  3. Click on the pipe for sending the email that you created in the pipe list.
  4. Open the schedule dialog by clicking on “Options…” next to the “Scheduled” item in the pipe properties.
  5. Set the schedule for when you would like the pipe to run and click “Save Changes”.
  6. Activate the schedule by turning on the button next to the “Scheduled” item and clicking the pipe “Save” button.

Going further

This tutorial shows you how to create a Flex.io pipe that regularly sends an email with an attachment from a file on Dropbox. Following a similar pattern, you can create pipes that send emails from files in other cloud storage, such as Google Drive, Box, Amazon S3, as well as from other sources like SFTP.

Here are some templates to get you started:

Send files from Amazon S3 as an email attachment
Send files from Box as an email attachment
Send files from Google Drive as an email attachment
Send files from SFTP as an email attachment