How we built a sophisticated cold email automation system using Python, OpenAI, and SendGrid that generates personalized sales emails with three distinct AI personalities
Let's face it—cold emailing is broken. Sales teams spend countless hours crafting personalized messages, only to see open rates hover around 20% and response rates barely crack 2%. The traditional approach of spray-and-pray templated emails is not just ineffective; it's actively harming your brand reputation.
But what if you could scale genuine personalization? What if AI could help you write emails that actually sound human, relevant, and compelling?
That's exactly what we set out to solve.
We built a Python-based system that uses multiple AI agents with different personalities to generate and send cold outreach emails. Think of it as having three different sales reps—each with their own style—working together to craft the perfect message for every prospect.
The system starts by analyzing your CRM data (we use CSV exports from Apollo.io, but any CRM works). It doesn't just grab random contacts—it intelligently filters based on:
Here's where the magic happens. Instead of using a single AI model, we deploy three different agents, each with a unique personality:
Each agent receives the same context—company information, prospect details, pain points—but produces dramatically different outputs.
Rather than randomly picking an email, we use another AI agent to evaluate and rank all three versions. The selection criteria includes:
The winning email gets sent via SendGrid, but not before passing through our duplicate prevention system. Every sent email is logged to prevent spamming the same prospect with similar messages.
def _personalize_email_content(email_content: str, contact: Contact) -> str:
"""Replace placeholders with actual contact data"""
personalization_map = {
"{first_name}": contact.first_name,
"{company}": contact.company,
"{industry}": contact.industry,
"{location}": contact.location
}
for placeholder, value in personalization_map.items():
email_content = email_content.replace(placeholder, value or "")
return email_content
sent_emails_log = set()
def is_email_already_sent(recipient_email: str, subject: str) -> bool:
"""Prevent duplicate emails to the same recipient"""
email_key = f"{recipient_email}:{subject}"
return email_key in sent_emails_log
The entire system is configurable through a single config file. Want to switch from plaintext to HTML emails? One line change. Need to target different industries? Update the filter criteria. Want to change your company's value proposition? Update it once, and all agents automatically use the new messaging.
After running this system for several weeks, we've seen:
You'll need:
pip install openai sendgrid pandas python-dotenv
# .env file
OPENAI_API_KEY=your_openai_key
SENDGRID_API_KEY=your_sendgrid_key
FROM_EMAIL=your@company.com
TO_EMAIL=test@recipient.com
config.py:
COMPANY_NAME = "Your Company"
COMPANY_DESCRIPTION = "What you do"
COMPANY_SERVICES = ["Service 1", "Service 2", "Service 3"]
python sales_team.py
The beauty of this system is its flexibility. You can:
This system represents just the beginning of what's possible with AI in sales automation. We're already working on:
The multi-agent approach to sales automation isn't just a technical novelty—it's a practical solution to the personalization-at-scale challenge that every sales team faces. By combining the creativity of multiple AI personalities with intelligent selection and robust automation, we've created a system that delivers genuinely personalized outreach at a fraction of the time and cost of traditional methods.
The code is open-source and available for you to experiment with. Whether you're a startup looking to scale your outreach or an established company wanting to modernize your sales process, this system provides a solid foundation for AI-powered sales automation.
The future of sales is here, and it's powered by intelligent agents working together to create human connections at scale.
Want to dive deeper? Check out the complete codebase and documentation on GitHub. Have questions or want to share your own experiments with AI-powered sales? Drop me a line—I'd love to hear about your experiences.