Your First Automation
This guide walks you through building a real automation end-to-end. We'll create a workflow that monitors a Gmail inbox for new emails containing OTP codes and extracts them automatically.
Prerequisites
- A FlowStack account (sign up free)
- A Gmail account with an App Password (required for IMAP access)
Step 1: Create the Automation
- Go to Dashboard → Automations
- Click + New Automation
- Select Workflow Builder (n8n engine) — this gives us the Code node for email parsing
Step 2: Add the Manual Trigger
The Workflow Builder opens with a Manual Trigger node already placed. This lets you test by clicking "Run" from the dashboard.
For production, you can later switch to a Schedule Trigger to check for new emails every few minutes.
Step 3: Add an IMAP Email Node
- Click the + button to add a new node
- Search for "Code" and select the Code node
- Paste this JavaScript code that connects to Gmail via IMAP:
const Imap = require('imap');
const { simpleParser } = require('mailparser');
const imapConfig = {
user: 'your-email@gmail.com',
password: 'your-app-password',
host: 'imap.gmail.com',
port: 993,
tls: true,
tlsOptions: { rejectUnauthorized: false }
};
// Connect and fetch the latest email
const imap = new Imap(imapConfig);
return new Promise((resolve, reject) => {
imap.once('ready', () => {
imap.openBox('INBOX', false, (err, box) => {
if (err) reject(err);
const searchCriteria = ['UNSEEN', ['SUBJECT', 'verification code']];
imap.search(searchCriteria, (err, results) => {
if (err) reject(err);
if (!results || results.length === 0) {
imap.end();
resolve([{ json: { otp: null, message: 'No new OTP emails found' } }]);
return;
}
const latest = results[results.length - 1];
const fetch = imap.fetch([latest], { bodies: '' });
fetch.on('message', (msg) => {
msg.on('body', (stream) => {
simpleParser(stream, (err, parsed) => {
const otpMatch = parsed.text.match(/\b(\d{6})\b/);
imap.end();
resolve([{
json: {
otp: otpMatch ? otpMatch[1] : null,
subject: parsed.subject,
from: parsed.from.text,
date: parsed.date
}
}]);
});
});
});
});
});
});
imap.once('error', reject);
imap.connect();
});
- Replace
your-email@gmail.comandyour-app-passwordwith your credentials
Step 4: Test the Automation
- Send yourself a test email with a 6-digit code in the subject (e.g., "Your verification code is 123456")
- Go back to Dashboard → Automations
- Find your automation and click Run
- Click View Runs to see the execution result
- The output will show the extracted OTP code, subject, sender, and date
Step 5: Activate for Production
To run this automatically:
- Open the automation in Workflow Builder
- Replace the Manual Trigger with a Schedule Trigger
- Set the interval (e.g., every 1 minute)
- Toggle the automation to Active from the dashboard
What You've Learned
- How to create an automation using the Workflow Builder
- How to use the Code node for custom logic
- How to test and monitor runs from the dashboard
- How to switch from manual to scheduled triggers
Next Steps
- Triggers — Learn about all trigger types
- Actions — Explore pre-built actions for 1,000+ apps
- Error Handling — Add retry logic and failure notifications