This workflow uses AI to analyze incoming emails and automatically apply relevant labels.
Trigger: A Gmail trigger checks for new messages every minute.
Content Extraction: When a new email arrives, the workflow extracts the plain text content.
AI Analysis: The extracted text is sent to an OpenAI model, along with instructions about the available Gmail labels. The AI model is configured to return an array of labels that best fit the email content.
Label Retrieval: The workflow retrieves the IDs of all available Gmail labels.
Matching Labels: The workflow matches the labels suggested by the AI with their corresponding IDs.
Applying Labels: Finally, the workflow applies the selected labels to the email in Gmail.
2. Creating Auto-Drafts of Replies
This workflow uses an OpenAI assistant, trained on a company’s product database, to generate draft replies to customer inquiries.
Trigger: A schedule trigger runs the workflow every minute.
Label Filter: The workflow focuses on emails with a specific label, such as “AI”.
Content Extraction: The workflow extracts the plain text content of the labeled email.
AI Assistant: The extracted text is sent to the OpenAI assistant. The assistant, using its knowledge of the product database, generates a response in markdown format.
Formatting: The markdown response is converted to HTML.
Email Structure: The workflow sets parameters like the recipient’s email address, subject, and message ID. The HTML response is formatted according to RFC standards for email messages.
Encoding: The message is converted to base64 encoding for compatibility with the Gmail API.
Draft Creation: The workflow uses the Gmail API to insert the formatted and encoded message as a draft in the corresponding email thread.
Label Removal: The workflow removes the “AI” label to prevent repeated draft generation for the same email.
The sources also describe a Gmail add-on that allows users to manually trigger these automations for specific emails and provide instructions on setting up webhooks to further customize the automation process.
Beyond OpenAI assistants, the sources also discuss the possibility of using AI agents with memory for even more personalized responses based on past interactions. These AI agents can leverage external databases and tools to retrieve relevant information and generate sophisticated responses.
The sources demonstrate how n8n’s flexibility and integration with AI can significantly streamline email management and enhance productivity.