How to save email attachments automatically

Save Email Attachments

In many organisations, storing email data from mailboxes to an external database is essential for a number of reasons, including integrating with CRM platforms, generating reports or analytics, or backing up, archiving, aggregating, or auditing data. However, email providers don’t often provide a method for saving email data to databases directly. You might miss an important document in the midst of the daily influx of emails.

No-code automation reduces manual tasks from your schedule and saves you time. You may create automated processes that fit with how tasks should be completed.

Baserow integrations are intended to overcome the limitation of exporting data to an external database. You can export any type of data to a database in simple steps without requiring constant manual effort. This gives you the freedom and flexibility to store emails in databases the way you want.

What will we do

In this tutorial, we will explore saving the contents of an email to a Baserow database. We’ll show you how to link email data to Baserow quickly and easily!

We will use Baserow, Make (formerly Integromat) and Email:

  • Search and filter through emails
  • Make integration monitor a specific inbox so that when new emails are added, it automatically processes those items
  • Extract relevant data from emails in real-time
  • Downloads attachments from emails and uploads them to Dropbox.
  • Insert a row in a pre-configured Baserow database and adds email content to the database.

enter image description here

This scenario watches an inbox and is triggered when a new email is received. Isn’t that cool? Let’s get started.

The first task before we begin the automation is to define all of the available fields in the table where the data will be populated.

1. Create a workspace and database in Baserow

Log into Baserow. If you haven’t already, create a Baserow account in either the self-hosted instance or hosted baserow.io SaaS instance.

After logging in to Baserow, you’ll see the Dashboard page, which gives you a snapshot of all your workspaces and databases.

Let’s start off by creating a new database. The first step to building a database is to create a workspace if you don’t have one already. Baserow allows for data collaboration across workspaces.

Create a workspace

Click the ‘+ Create workspace’ button to create your workspace within which you can store multiple databases. Enter a workspace name then click the ‘Add workspace’ button.

If you are just getting started with Baserow, we recommend you read our user documentation on how to create a Workspace and how to add collaborators to your workspace.

Create a database

Within a workspace, click the ‘+ Create new’ button then select ‘Database’ from the dropdown modal. Enter a descriptive name for the new database. You can alternatively add a database from a template or Import a database from Airtable.

For this tutorial, we will name our database “Email Database”.

enter image description here

Let’s get into populating data in your Baserow databases.

2. Add customizable field types

The next step is to create a table within the database and add fields to the table.

Field Name Field Type
Sender Name Single line text
Sender Email Email
Subject Single line text
Body Preview Long text
Date received Date
File URL URL
Open file Formula

The formula, button(field('File URL'),'open file'), creates a button using the URI (first argument) and label (second argument). This uses a formula syntax supports using cell values from other fields

This will create an interactive field type based on the File URL field that lets you trigger specific actions, such as downloading or rendering email attachments in your browser, directly from your Baserow table.

enter image description here

Now, let’s proceed to automate saving emails and files to the database.

3. Create a new Make (formerly Integromat) Scenario

Make (formerly Integromat) can monitor emails in real-time. This will automatically process incoming emails or newly added appointments, tasks, or contact items and add the data for the selected fields to the database.

To get started, create a new Make.com account or log into your existing account:

enter image description here

Now you need to add the first module to the scenario. Go to Scenarios and create a new scenario. A Make scenario is comprised of a series of modules that indicate how data should be transferred and transformed between apps/services.

For this tutorial, we will track emails in an inbox and save the data in our database. The workflow supports and works with any compatible email provider such as Gmail, Microsoft 365 email, YahooMail, Zoho Mail and more. You can alternatively connect your preferred email app on Make.

  1. Select the app that will trigger your scenario. Click the first “+” sign and select Email ****as the trigger
  2. Choose one of the actions from the list. In this case, select the Watch Messages action. This triggers the workflow when a new message is sent or received.
  3. Create a connection or select one of your previously configured connections from the dropdown options. For more information on how to create a connection to Email, see the Make online Help.

enter image description here

Next, select messages to watch, watch folder, search query and the maximum number of results to be worked with during one execution cycle. For this tutorial, we are working with these values:

  • Folder: Inbox
  • Criteria: All emails
  • Select Yes to mark email message(s) as read when fetched
  • Maximum number of results: 100

You can choose to process only emails sent from a specified email address, only emails sent to a specified email address, only emails containing a specified character string in their subject field, or only emails containing a specified character string (anywhere).

Click the ‘Ok’ button then choose where you would like Make to start processing all emails. For this tutorial, we will select From now on, then click ‘Ok’.

enter image description here

Next, let’s iterate the attachments.

4. Add a router module

The Router module allows you to branch your flow into several routes and process the data within each route differently. You can specify the filter conditions to define which files are permitted to pass through a specific module.

We want to set up 2 routes

  • Route A: If the email contains no attachments, send data directly to the database
  • Route B: If the email contains attachments, upload the file to dropbox then send data to the database

To connect the Router after the Email module, Click on the module’s right “ear” and choose Flow Control > Router from the list of modules.

enter image description here

Now, let’s continue the flow with route A if the condition is met.

5. Route A: Add email data to database

We will export the email data to the database and run a workflow when data is received.

Like with the Email module, we need to add a Baserow connection.

  1. Select the app that will trigger your scenario. Click the “+” sign and select the Baserow app

  2. Choose one of the actions from the list. In this case, select the Create a row action.

  3. Create a connection or select one of your previously configured connections from the dropdown options. You will need to enter your Baserow API URL retrieved from your API documentation. If you are using baserow.io, you can leave the default URL. You will also need to enter your Baserow API token. It can be found by clicking on your account in the top left corner -> Settings -> API tokens. For more information on how to find your database token, see this support article.

  4. Enter the table ID where the row must be created in. You can find the ID by clicking on the three dots next to the table. It’s the number between brackets. For more information on how to find your Baserow table ID, see the support article.

    enter image description here

  5. Next, map the results from the Email module to Baserow.

    • Sender Name: To ensure that the sender name does not return empty, populate the field with either the Sender name or Sender’s email. This performs a logical disjunction on two expressions.
    • Body preview = Text content
    • Date received: Baserow table date field accepts a date in ISO format (e.g. 2020-01-01). Using the ‘formatDate’ function, we parse the ‘date’ from our email and define an output format. In this case, we used the format ‘YYYY-MM-DD’ as output. Learn how to format your data and time fields.
    • Subject = Subject
    • Sender Email = Sender’s email address

    enter image description here

Click ‘Ok’. Run Once then check your table to see if the correct data was added.

6. Route B: Iterate attachments

Iterator allows you to split a large bundle of data into multiple smaller bundles. The goal of iteration is to prompt Make to upload all of the attachments from a single email to Dropbox in a single operation, regardless of the number of attachments in the email.

To add the next module,

  • Select the Email > Iterate Attachments module as the source module. This will iterate the attachments array from the Email module to generate multiple bundles of data.
  • The previous Email module will be automatically selected as the source module. Simply click OK:

enter image description here

Add a filter on a route after the Router to filter bundles as on any other route. Click on the route, add conditions to filter your data as it passes through the routes.

To insert the filter between the Router and Email modules, click on the wrench icon below the route connecting the two modules (or right-click the route) and choose “Set up a filter” from the menu.

Set the condition as: Attachment File name exists.

enter image description here

Click on the “OK” button to save the filter setup to pass through this route only when a new email with attachments is received:

Next, we want to add another module to store extracted attachments to a file system.

7. Route B: Upload files to Dropbox

When we run the workflow, we want to store the attachment from the Email module in a Dropbox folder and map the URL of the file to the database.

This step is useful to save any file or image format including, .ics, .jpg, .png, .pdf, .docx, .mp4, .mp3, .mov, .wav, and large file sizes. A URL containing the location of the saved file can be used to download the file.

As in the previous step, add a connection and allow Make to access your Dropbox account:

  • Select Dropbox > Upload a File module.

  • Create a connection. For more information on how to create a connection to Dropbox, see the Make online Help.

  • Choose a destination folder for the attachments by clicking on the / + ****icon or map the folder name by toggling the Map switch to fetch an element from another module.

  • The File will be automatically selected as Email — Iterate Attachments. Alternatively, select Map under File which provides an option to modify the file name and data. Mapping a unique identifier, e.g. date or email ID, to the file name may be useful to identify the sender.

    enter image description here

Click ‘Ok’ and then Run once to preview the results.

In your Dropbox account, modify the folder permissions to viewable with a link. Share and manage access to this folder so that anyone who has access to your Baserow database can view the file. Learn how to share a link to a Dropbox file or folder.

8. Route B: Export the email data to database

Now, let’s use the Baserow module to send email data to the database.

Select the app that will trigger your scenario. Click the “+” sign and select the Baserow app.

Next, select the Create a row action and map the results from the trigger module to fields in your Baserow database as in Step 5 above.

To map the file URL,

  1. Copy the public share link that allows viewing. The original shared link URL may contain query string parameters already (for example, dl=0).

  2. Paste the shared link then add: *preview=encodeURL(*name) as a query parameter in your URL like this:

    https://www.dropbox.com/sh/ovc912dve526yod/AABjmzWmbcD7IJYZek2DCBSEa?dl=0&preview=ringr_participant_292583_0.ics
    

    encodeURL function encodes special characters in a text to a valid URL address.

enter image description here

Tip: You can append the dropbox URL to force the attachment to download or render in your browser. To bypass the preview page and allow your browser to directly render your files, use raw=1 as a query parameter in your URL. To force a browser to download the contents of a link rather than display it, use dl=1 as a query parameter in your URL.

Click “Ok” to save this module.

9. Test & schedule Scenario to monitor Inbox

Your scenario is set up and ready to go, but we still need to run a quick test. Run the scenario, you will see that Make will load the email and store the data in your Baserow database.

enter image description here

Check your table to see if the correct data was added.

You can specify when and how frequently an activated scenario runs. To do so, go to the scenario detail page and locate the Schedule tab.

To set the schedule, change the Run Scenario and set the time when it should run. Click on the clock icon and set your preferred schedule.

enter image description here

Save and activate the scenario by toggling on the switch at the bottom left corner:

When you execute the scenario, whenever an Email is received in a monitored folder, the changes are immediately reflected in the corresponding row in the database. This allows you to maintain synchronisation between Email items and the database with minimal manual work.

Post-process email data

Now that the data is stored on your Baserow database, you have several options to use any data from the workflow. You can optionally add additional modules at the end of the scenario to:

  • Copy, move or delete the email
  • Send notifications to a messaging channel, e.g. Slack or Microsoft Teams
  • Auto-respond or send an email when all operations in the scenario have been completed

Filter views

Tip 💡: In your Baserow database, add a new view to your table to separate the rows where File URL is empty and the rows where File URL is not empty. Filters allow you to show rows that apply to your conditions. Learn more about customizing your views.

enter image description here

The button formula field will appear in your table as a clickable button as shown by the “Open file” button above. This button makes integrating with other systems much easier because you can click it to connect to a specific attachment in a file system.

Hide fields

Hide empty fields in your views to tidy up your database. Learn more about showing and hiding fields.

enter image description here

Key Takeaways

There isn’t always a direct way to export email data from an email provider to a database. You may need to download the file first and then upload it to the database.

With Make.com, you can connect the Baserow module with numerous apps to create scenarios, run automated tasks and define what happens when data is updated. This will save you the time and effort of manually copying and pasting data from emails to your database.

This automation is especially helpful if you want to track or keep a backup of your current email items.

What’s your use case? Tell us how you use Baserow