At a glance
- Trigger
- Email Trigger (IMAP) (Email Trigger (IMAP))
- Nodes
- 9
- Apps
- Email (IMAP) and OpenAI
- AI nodes
- 1
- Credentials
- 3 types
- Category
- Email automation
Apps and integrations
Node types used
How it works
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Workflow Description
This n8n workflow automates the drafting of email replies for Fastmail using OpenAI's GPT-4 model. Here’s the overall process
- Email Monitoring: The workflow continuously monitors a specified IMAP inbox for new, unread emails.
- Email Data Extraction: When a new email is detected, it extracts relevant details such as the sender, subject, email body, and metadata.
- AI Response Generation: The extracted email content is sent to OpenAI's GPT-4, which generates a personalized draft response.
- Get Fastmail Session and Mailbox IDs: Connects to the Fastmail API to retrieve necessary session details and mailbox IDs.
- Draft Identification: Identifies the "Drafts" folder in the mailbox.
- Draft Preparation: Compiles all the necessary information to create the draft, including the generated response, original email details, and specified recipient.
- Draft Uploading: Uploads the prepared draft email to the "Drafts" folder in the Fastmail mailbox.
Setup notes
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Prerequisites
- IMAP Email Account: You need to configure an IMAP email account in n8n to monitor incoming emails.
- Fastmail API Credentials: A Fastmail account with JMAP API enabled. You should set up HTTP Header authentication in n8n with your Fastmail API credentials.
- OpenAI API Key: [redacted] API key from OpenAI to access GPT-4. Make sure to configure the OpenAI credentials in n8n.
Nodes in this workflow
The 9 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:
- Session (HTTP Request)
- Get Mailbox IDs (HTTP Request)
- Split Out (Split Out)
- Email Trigger (IMAP) (Email Trigger (IMAP))
- Get fields from source email (Edit Fields (Set))
- OpenAI (OpenAI)
- Filter for drafts folder (Filter)
- upload draft email (HTTP Request)
- gather data for draft email (Edit Fields (Set))
Credentials you need
- HTTP Header Auth – used by Get Mailbox IDs, Session and upload draft email
- IMAP – used by Email Trigger (IMAP)
- OpenAI API – used by OpenAI
Configure your own credentials after importing. Create each credential in n8n, then select it in the node.
How to import into n8n
- Download the JSON file with the button above.
- In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
- Open each node that shows a warning and select or create its credential.
- Read the notes on the canvas, test the workflow with sample data, then activate it.
Do you need somewhere to run it? Read our guide to self-hosted n8n.