n8nflow.net logo

Gmail to Google Drive Email Export Workflow

by Akhil Varma Gadirajuβ€’Updated: Last update 4 months agoβ€’Source: n8n.io
Loading workflow viewer...

Getting Started

πŸ“¬ Gmail to Google Drive Email Export Workflow (n8n)

🧩 Overview

This n8n workflow automates the process of:

  1. Retrieving all emails from a specific sender using Gmail.
  2. Extracting essential fields like subject, message, and date.
  3. Formatting the email date to the desired time zone (e.g., IST).
  4. Exporting the parsed data as a CSV file.
  5. Uploading the file to a specified folder in Google Drive.

πŸ›  Nodes Breakdown

1. Start Workflow (Manual Trigger)

  • Type : Manual Trigger
  • Purpose : Initiates the workflow manually.

2. Gmail Node (Get All Emails)

  • Type : Gmail
  • Operation : getAll
  • Filters :
    • sender: [[email protected]](/cdn-cgi/l/email-protection)
  • Returns : All emails from the specified sender.
  • Credentials : Gmail OAuth2 - Akhil

3. Parse Data (Set Node)

  • Purpose : Extracts key fields from the email JSON.
  • Mapped Fields :
    • id: Email ID
    • subject: Email subject
    • message: Email text
    • time: Email date

4. Convert Time Field (Code Node)

  • Purpose : Converts the email time (ISO 8601) to a human-readable format.

  • Output Format :

    • Local time using Asia/Kolkata timezone.
    • Format: "Month Day, Year, Hour:Minute AM/PM"
  • Customizable : Change the timezone as needed:

    timeZone: 'Asia/Kolkata'


5. Convert to File

  • Type : Convert to File Node
  • Purpose : Converts JSON data to a downloadable .csv file.
  • Output File : CSV containing id, subject, message, and time.

6. Google Drive

  • Type : Google Drive
  • Purpose : Uploads the generated CSV file to Google Drive.
  • Drive : My Drive
  • Folder : Root
  • File Name : Current timestamp + _n8n_export.csv

7. End Workflow (NoOp)

  • Purpose : Final node to explicitly end the workflow.

βœ… Use Cases

  • Personal Email Archiving : Back up or export emails from a specific sender (e.g., invoices, reports).
  • Audit Logs : Save conversations for compliance.
  • Team Reports : Aggregate project emails into a central file store.

πŸ”§ Customization Guide

CustomizationHow to Do It
Change Sender EmailUpdate the sender field in the Gmail node.
Filter by Date/SubjectAdd filters in the Gmail node settings.
Change Time ZoneEdit timeZone in the Code node.
Add More Email FieldsModify the Set node to include more fields.
Change File FormatUse a different format in the Convert to File node.
Rename Output FileAdjust the name in the Google Drive node.
Change Upload FolderSet a different folderId in the Google Drive node.

πŸš€ Deployment Tips

  • Schedule the Workflow : Replace Manual Trigger with a Cron node.
  • Avoid Duplicates : Store email IDs and skip duplicates using conditional logic.
  • Security : Use environment variables for sensitive credentials.

πŸ§ͺ Testing Steps

  1. Manually trigger the workflow.
  2. Verify email data is parsed and formatted.
  3. Confirm CSV is generated correctly.
  4. Ensure the file is uploaded to Google Drive.

🧰 Requirements

  • Connected Gmail and Google Drive OAuth2 credentials.
  • n8n instance (self-hosted or cloud).
  • Required nodes available in the n8n environment.

πŸ’‘ Need more features? You can add:

  • Error handling
  • Slack/Email notifications
  • Conditional filters
  • Google Sheets integration instead of Drive