Private Secret Santa Assignment and Gmail Notification System - n8n Workflow

A comprehensive n8n workflow utilizing custom code to generate private Secret Santa assignments (derangements) and instantly notify participants via Gmail. Perfect for holiday automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Event Organizers: Individuals managing small or medium-sized group gift exchanges.

  • Automation Enthusiasts: Users looking for advanced examples of using the n8n node Code feature for complex mathematical logic (derangements).

  • Technical Teams: Developers seeking robust, verifiable n8n templates for email-based campaigns.

Overview

Managing Secret Santa pairings manually can be time-consuming and often risks revealing the pairings prematurely. This specialized n8n workflow solves this by providing a highly automated, private solution. It uses an input list of participants (Name and Email) and leverages a custom JavaScript n8n node to execute a derangement algorithm, ensuring perfectly randomized assignments where no one draws themselves.

Crucially, after sending the assignment via the Gmail n8n node, the workflow immediately deletes the message from the sender's 'Sent' folder. This ensures maximum privacy, making this a truly 'Secret' Santa system. This automated process saves time, guarantees fairness, and provides a consolidated verification log at the end of the n8n workflow execution.

How it Works

This n8n workflow is designed to run manually using a dedicated n8n trigger, initiating the sequential steps:


  1. Input Definition: The process starts with the 'Emails and name' n8n node, where the user defines all participants as Name-to-Email key-value pairs.

  2. Assignment Generation: The 'Random' Code n8n node executes complex JavaScript. This code reads the input, verifies email validity, and applies a derangement algorithm to create pairings (Giver -> Receiver), ensuring no self-assignment occurs.

  3. Iteration: The 'loop mails' Split In Batches n8n node takes the list of successful pairings and processes them one by one.

  4. Private Notification: For each pairing, the first Gmail n8n node ('Send a message') sends a private HTML email to the 'Emisor' (Giver), revealing the 'Receptor' (Receiver).

  5. Stealth Mode: Immediately following the sending, the second Gmail n8n node ('Delete a message') uses the message ID returned by the previous step to delete the email from the sender’s account, enhancing privacy.

  6. Tracking: The 'Who?' Set n8n node captures the assignment in text format (email -> email) for internal logging.

  7. Verification Summary: After all pairings are sent, the 'Name to INT' Code n8n node processes all the logging data. It obfuscates the emails by assigning numerical IDs and compiles the full list of assignments.

  8. Final Confirmation: The 'Send a message results' Gmail n8n node sends a final confirmation email to the administrator (e.g., [email protected]) containing the obfuscated verification summary, confirming successful execution of the entire n8n workflow.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Download the provided JSON file and import it directly into your n8n instance.

  2. Credentials Setup: This n8n template requires Gmail OAuth2 credentials. Locate the 'Send a message' and 'Send a message results' Gmail n8n nodes and configure a working Gmail OAuth2 account. This account will be used to send the assignment emails.

  3. Configure Participants: Navigate to the 'Emails and name' Set n8n node. Replace the placeholder Name/Email pairs with your actual Secret Santa participants (e.g., {"Sarah":"[email protected]"}). Ensure the keys are the names and the values are the emails.

  4. Configure Admin Email: In the 'Send a message results' Gmail n8n node, update the sendTo field ([email protected]) to your personal address to receive the final verification report.

  5. Execution: Use the 'Run' n8n trigger to start the process. This specific n8n workflow is best executed manually to control the timing of the Secret Santa announcement.

Node Details

Run (manualTrigger n8n trigger): The starting point of the n8n workflow, used to manually initiate the Secret Santa assignment process.
Emails and name (Set n8n node): Essential configuration node. Defines the key input data structure (Name: Email). Key configuration involves updating the 'Assignments' section with all participant details.
Random (Code n8n node): The core logic engine. Function: Executes a robust JavaScript derangement algorithm to generate non-self-assigned, unique Secret Santa pairings. Key Configuration: Contains custom JS code for list processing and randomized assignment generation.
loop mails (Split In Batches n8n node): Function: Iterates through each successful pairing generated by the 'Random' code n8n node, ensuring each assignment is handled individually.
Send a message (Gmail n8n node): Function: Sends the HTML-formatted assignment email to the Giver ($json.emisor). Key Configuration: Uses Expressions ={{ $json.emisor }} for recipient and ={{ $json.nombreReceptor }} in the HTML body to personalize the message.
Delete a message (Gmail n8n node): Function: Deletes the email sent in the previous step from the sender's account to maintain secrecy. Key Configuration: Uses Expression ={{ $json.id }} to target the specific message ID for deletion.
Name to INT (Code n8n node): Function: Processes the complete log of assignments, assigns sequential numerical IDs to emails for anonymity, and consolidates the pairings into a single verification summary. Key Configuration: Contains custom JS code for email extraction and ID mapping.
Send a message results (Gmail n8n node): Function: Sends the final execution summary to the administrator, confirming the assignments were successfully delivered using the obfuscated ID system.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
Oriol Seguí
Oriol Seguí

Completion of a higher degree on the way to university (computer engineering)

Featured*