Forward Important Emails to Slack Automatically
Introduction
Important emails often get lost in crowded inboxes. By forwarding critical messages to Slack, you ensure your team sees them immediately. This tutorial shows you how to set up smart email-to-Slack forwarding with n8n.
Prerequisites
- An n8n instance
- Email account with IMAP access (Gmail, Outlook, etc.)
- Slack workspace with incoming webhooks
Workflow Overview
Email Trigger (IMAP) → Filter Important → Format Message → Post to SlackStep-by-Step Setup
Step 1: Configure Email Trigger
- Add an Email Read IMAP node
- Configure your email credentials:
- Host:
imap.gmail.com(for Gmail) - Port:
993 - User: Your email
- Password: App-specific password
- Host:
- Set polling interval (e.g., every minute)
- Mailbox:
INBOX
Step 2: Filter Important Emails
Add a Filter node to only forward relevant emails:
Conditions (match ANY):
// From important domains
$json.from.includes('@important-client.com')
// Contains urgent keywords
$json.subject.toLowerCase().includes('urgent')
// From VIP senders
['ceo@company.com', 'support@vendor.com'].includes($json.from)Example filter configuration:
fromcontains@important-domain.comORsubjectcontainsURGENTORsubjectcontainsACTION REQUIRED
Step 3: Format for Slack
Add a Set node to prepare the message:
// Truncate long email bodies
const maxLength = 500;
let body = $json.text || $json.html || 'No content';
if (body.length > maxLength) {
body = body.substring(0, maxLength) + '...';
}
// Clean HTML if present
body = body.replace(/<[^>]*>/g, '');
return {
from: $json.from,
subject: $json.subject,
preview: body,
date: $json.date
};Step 4: Post to Slack
Add a Slack node:
Channel: #important-emails
Message:
📧 *New Important Email*
*From:* {{ $json.from }}
*Subject:* {{ $json.subject }}
*Received:* {{ $json.date }}
>>> {{ $json.preview }}Or use Block Kit for richer formatting:
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "📧 New Important Email"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*From:*\n{{ $json.from }}"
},
{
"type": "mrkdwn",
"text": "*Subject:*\n{{ $json.subject }}"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "{{ $json.preview }}"
}
}
]
}Advanced Filtering
Filter by Sender Domain
const importantDomains = [
'client1.com',
'client2.com',
'partner.com'
];
const senderDomain = $json.from.split('@')[1];
return importantDomains.includes(senderDomain);Filter by Keywords
const urgentKeywords = ['urgent', 'asap', 'critical', 'emergency', 'action required'];
const subject = $json.subject.toLowerCase();
return urgentKeywords.some(keyword => subject.includes(keyword));Exclude Newsletters
const excludePatterns = [
'unsubscribe',
'newsletter',
'marketing',
'noreply'
];
const content = ($json.subject + ' ' + $json.from).toLowerCase();
return !excludePatterns.some(pattern => content.includes(pattern));Route to Different Channels
Send emails to different channels based on content:
const subject = $json.subject.toLowerCase();
if (subject.includes('support') || subject.includes('ticket')) {
return '#support';
} else if (subject.includes('sales') || subject.includes('deal')) {
return '#sales';
} else if (subject.includes('invoice') || subject.includes('payment')) {
return '#finance';
} else {
return '#general-emails';
}Handle Attachments
Notify about attachments without forwarding them:
const hasAttachments = $json.attachments && $json.attachments.length > 0;
const attachmentInfo = hasAttachments
? `\n📎 *Attachments:* ${$json.attachments.length} file(s)`
: '';
return {
...$json,
attachmentInfo: attachmentInfo
};Gmail-Specific Setup
Create App Password
- Go to Google Account → Security
- Enable 2-Step Verification
- Go to App Passwords
- Generate password for “Mail”
- Use this password in n8n
Use Gmail Labels
Filter by Gmail label instead of scanning all emails:
Mailbox: [Gmail]/ImportantTroubleshooting
Connection Failed
- Verify IMAP is enabled in email settings
- Check host and port are correct
- Use app-specific password for Gmail
Missing Emails
- Check spam/junk folder
- Verify filter conditions aren’t too strict
- Check polling interval
Duplicate Messages
- Add a seen/processed check
- Use email Message-ID for deduplication
Best Practices
- Start with strict filters - Expand gradually to avoid noise
- Use a dedicated channel - Don’t spam general channels
- Include original link - Let users read full email in client
- Handle errors gracefully - Don’t crash on malformed emails
- Monitor the workflow - Ensure it’s running reliably
Conclusion
Email-to-Slack forwarding ensures critical messages get immediate attention. With n8n’s flexible filtering, you can fine-tune exactly which emails get forwarded and to which channels.
Download the complete workflow from our n8n Workflow Gallery.