1. Opening Problem Statement
Meet Sarah, a busy sales development representative (SDR) at an AI consulting firm. Sarah spends hours every week crafting sales emails tailored to her prospective clients. However, despite her efforts, many emails remain generic or miss the mark because she lacks deep insight into each customer’s communication style, challenges, and preferences. This leads to low response rates and wasted effort. With dozens of leads to contact each day, personalization becomes cumbersome and error-prone, costing Sarah and her company valuable time and potential revenue.
Sarah’s core struggle? How to create truly personalized sales emails quickly without sacrificing quality or drowning in manual research. This is exactly where our n8n automation workflow shines.
2. What This Automation Does
When this workflow runs, it transforms raw email data from your mailbox into powerful, tailored sales communications by leveraging AI-driven persona analysis and message generation. Here is what happens step-by-step:
- Targeted Customer Selection: Pulls decision-makers from HubSpot CRM to form a relevant contact list.
- Email Correspondence Retrieval: Automatically extracts up to 20 recent emails from your Gmail account for each targeted customer, capturing communication history.
- Persona Building: Uses Google Gemini AI to analyze email contents and build a detailed customer persona including decision-making style, communication preferences, pain points, and motivations.
- Sales Email Generation: Generates a custom sales email draft that matches the customer’s persona, highlighting relevant product benefits and using their preferred tone and style.
- Draft Email Creation: Saves the generated email as a Gmail draft for review, allowing the sales rep to approve, tweak, or send.
- Looping Through All Contacts: Repeats the process for each contact seamlessly with batch processing.
By automating these tasks, Sarah can save hours daily and craft outreach emails that resonate personally, increasing the chance of engagement and closing deals faster.
3. Prerequisites ⚙️
- n8n Account: Set up an n8n automation instance. You can self-host it or use n8n cloud.
- HubSpot Account 🔑: Connected via app token to fetch targeted decision-maker contacts.
- Gmail Account 📧: OAuth2 credentials configured in n8n to access emails and create draft messages.
- Google Palm API (Google Gemini) 🔐: API access set up with your Google Cloud project for AI-powered language models.
- Basic knowledge of n8n: While beginner-friendly, some comfort with node configuration helps.
4. Step-by-Step Guide
Step 1: Trigger the Workflow Manually
Navigate to n8n and find the workflow. Click When clicking ‘Test workflow’ node and press the “Execute Workflow” button. This starts the process manually so you can test it.
You should see the workflow activate and proceed through the defined steps without error. A common mistake here is forgetting to provide OAuth credentials, which leads to authentication errors.
Step 2: Retrieve Target Decision-Makers from HubSpot
In the Get Contacts HubSpot node, ensure your app token is connected. The node is configured to filter for customers with the role of DECISION_MAKER.
After execution, you will get a list of contacts relevant for sending sales emails. Ensure your token has proper scopes to access contact data. If no contacts appear, verify your HubSpot lists and filters.
Step 3: Split Contacts into Batches for Processing
The For Each Contact node is a SplitInBatches node that processes contacts one at a time. This controls the flow and manages resource use.
If contacts get stuck here, check batch size and follow-up nodes for errors.
Step 4: Fetch Email Correspondence from Gmail
The Get All Customer’s Correspondence node connects to Gmail via OAuth2, configured to fetch emails from the current contact’s email address. It pulls up to 20 emails matching the filter from:{{ $json.email }}.
This step gathers real communication data to feed into AI analysis. A common issue is incorrect filter syntax or insufficient Gmail API permissions, which should be corrected in node settings or Google Cloud configurations.
Step 5: Build a Customer Persona Using AI
The Google Gemini Chat Model node sends the raw email text data to Google’s Gemini 2.0-flash model. This node is configured to extract persona attributes like decision-making style and pain points using a comprehensive prompt.
The model’s output is parsed by the Analyse and Build Persona node (Information Extractor), which maps AI responses to defined persona fields such as communication_preferences and professional_goals_motivations.
This persona helps craft highly relevant sales emails. If you see errors here, confirm API key validity and that the prompt matches node requirements.
Step 6: Generate a Personalized Sales Email
The Google Gemini Chat Model1 node takes the completed persona and the product description from the Variables node. It uses an AI prompt telling the model to act as a sales rep drafting a closing email tailored to the customer profile.
The Generate Sales Email node extracts the subject and body fields with HTML formatting for rich email content, ensuring professional and engaging messaging.
Step 7: Create a Draft Email in Gmail for Review
The Create Draft Email For Review Gmail node creates an email draft using the generated subject and body, addressed to the customer’s email from Variables. This step leaves control in human hands, allowing review before sending.
Be sure your Gmail OAuth credentials include permission to manage drafts.
Step 8: Loop Back for Next Contact
Once the draft is created, the workflow loops back to the For Each Contact node, repeating the process for all contacts detected in HubSpot.
Completion of the loop means all targeted contacts have personalized outreach drafts ready.
5. Customizations ✏️
- Change Product Details: In the Variables node, update the
product_to_sellstring to reflect your current offering, guiding the email tone and messaging. - Adjust Email Retrieval Limit: In the Get All Customer’s Correspondence Gmail node, modify the
limitfield to fetch more or fewer emails based on your preference for context depth. - Send Emails Automatically: Modify the Create Draft Email For Review node to send emails directly by changing the resource from
drafttosend. Use with caution to avoid errors without review. - Customize Persona Attributes: Edit the attributes list in the Analyse and Build Persona Information Extractor to focus on other persona qualities relevant for your sales approach.
- Integrate Other CRMs: Replace the HubSpot node with other CRM connectors supported by n8n, adjusting data mappings accordingly.
6. Troubleshooting 🔧
Problem: “Authentication Error: Invalid OAuth Token.”
Cause: Gmail or HubSpot OAuth credentials expired or misconfigured.
Solution: Re-authenticate the accounts in n8n credentials section. Double-check tokens and refresh permissions.
Problem: “No emails found for given contact.”
Cause: Gmail filter query syntax error or that contact has no matching emails.
Solution: Verify the q filter with a test search in Gmail web interface. Adjust email addresses or filters as needed.
Problem: “AI node returns incomplete persona data.”
Cause: Google Gemini API rate limits or prompt mismatch.
Solution: Check API usage quota. Review and simplify the prompt. Retry after some time.
7. Pre-Production Checklist ✅
- Verify all OAuth credentials have valid tokens and required scopes.
- Test HubSpot search criteria returns expected decision-maker contacts.
- Confirm Gmail filter query retrieves recent emails from contacts correctly.
- Run a manual trigger test, monitor AI node outputs for persona completeness.
- Review generated drafts in Gmail, ensuring formatting and content are correct.
- Backup your workflow before deploying any major changes.
8. Deployment Guide
Activate the workflow by enabling it in n8n to run on your schedule or triggers you prefer.
Monitor runs initially using n8n’s execution history to catch any errors or unusual behavior.
Adjust batch sizes or API credentials as your contact list scales for smooth performance.
9. FAQs
Q: Can I use a different CRM instead of HubSpot?
A: Yes, n8n supports many CRM integrations like Salesforce or Pipedrive. You must adjust the contact retrieval node accordingly.
Q: Does this workflow consume a lot of API credits?
A: The Google Gemini API calls can add up based on contact volume. Monitor usage and optimize prompt length to control costs.
Q: Is my customer data secure?
A: All data stays within your n8n instance and uses secure authenticated connections. Be cautious with sensitive data shared with third-party AI APIs and apply appropriate data handling policies.
10. Conclusion
By completing this workflow setup, you now have a powerful tool that automates crafting truly personalized sales emails tailored to each prospect’s unique persona derived from their actual email communications. This cuts down research and writing time from hours to minutes, making your outreach more relevant and effective.
Sarah can focus more on closing deals rather than manual data gathering. You’ve just harnessed n8n’s automation combined with Google Gemini AI to deliver smart, custom sales outreach at scale.
Next, consider expanding this workflow to automatically send follow-up emails, integrate SMS reminders, or even sync responses back into your CRM for complete contact lifecycle management. Happy automating!