Blog'a Dön
BLOG

How We Built Email Template Automation with n8n and Google Drive

21 Kasım 2026 5 dk okuma
How We Built Email Template Automation with n8n and Google Drive

How We Built Email Template Automation with n8n and Google Drive

At DigiWise, we built a workflow that takes an HTML email from Google Drive and turns it into a reusable template in our application. This gave us a consistent way to import the template name, subject line and body together through our REST API.

We started with a dedicated folder for email templates

We used Google Drive as the handoff between the person preparing an email and the application that stores the template. Each email starts as an HTML file. The n8n workflow searches a dedicated folder, filters for HTML files and processes them one at a time. The exported workflow includes a 30-minute schedule and a manual trigger for testing with a known input.

The endpoint creates a reusable template record. Recipient selection, campaign scheduling and message delivery take place downstream. We kept those decisions outside the import so that a file appearing in Drive creates no outgoing message.

We converted each HTML file into a template record

Download the HTML and resolve the subject line

After downloading the source file, n8n reads its HTML and looks for explicit metadata. The template-name field can supply a name for the application, while email-subject or subject can supply the subject line. When no subject is declared, the workflow falls back to the HTML title, the first H1 or the filename stem. It checks that the resulting subject is between 1 and 255 characters before making the API request.

Create the record through the REST API

n8n sends the template name, subject, HTML body and active flag as JSON to the DigiWise mail-template endpoint in an authenticated request. The application owns template creation. The workflow checks the HTTP status, the success flag and the returned record ID before it reports a newly created template.

Example. A service company could prepare service-visit-reminder.html with the template name “Service Visit Reminder” and the subject “Your upcoming service visit.” A successful import makes that template available in the application. The team can then choose when to use it and who should receive the message.

We handled repeat scans and name conflicts separately

Use the source file ID for a stable request key

A scheduled workflow can encounter the same file on successive runs. We derive the request’s Idempotency-Key from the Google Drive file ID so that retrying an import for the same source uses the same key. A newly uploaded copy has a different Drive ID, even when its filename or content is identical. The workflow is designed around template creation. Editing the source file does not establish a template update process.

Review HTTP 409 responses as name conflicts

The workflow records HTTP 409 as a name conflict and calls for a check in the administration panel. A record with the same name could have come from a different source. We treat creation as confirmed when the API returns HTTP 201 with the expected success data and a record ID.

The exported workflow configures bounded retries on the Drive download and HTTP request nodes. It also passes full HTTP responses to a separate result check. That means an HTTP response such as a 409 can be classified explicitly, while an operation that throws an error follows the node's retry behavior. See the n8n error handling documentation.

How to test this approach with your own templates

  1. Start with a single fixture. Use a sample HTML file with an explicit template name and subject. Run the manual trigger and check that the returned record ID points to the expected name, subject and HTML body.
  2. Exercise the fallback rules. Use a fresh fixture without a subject meta tag and verify the expected title fallback. Preview the HTML on a narrow screen and in the email clients your team uses.
  3. Replay the same source. Run the same Drive file through the workflow again and verify that it creates no second record. Then use a different file with the same template name to check how the conflict is reported.
  4. Test a download failure. In a test environment, make the source unavailable and check that the execution shows where the import stopped. Keep the source file ID with your diagnosis so you can trace the item across runs.

Conclusion

Google Drive gives our team a place to prepare HTML. n8n handles intake and validation, and the DigiWise REST API creates the template record. That division gives a business one place to author a template, a way to trace where it came from and a separate decision about when to send it.

If your team regularly copies email HTML between tools or rebuilds the same operational messages, talk to DigiWise about automating your template workflow. Start with one recurring message and verify the import before expanding to the rest of your template library.