Automated Email Follow-up
This prompt generates a Python script that automates sending personalized follow-up emails to new leads based on their specific inquiry topic from a CSV file.
Prompt
Create a robust Python script to automate the initial follow-up emails to new leads. The script should be well-commented so I can understand each part.
Core Functionality:
Data Source: The script must read new lead information from a CSV file named leads.csv. The CSV will have the following columns: lead_id, first_name, email_address, and inquiry_topic.
Email Logic: The script needs to send a unique email for each inquiry_topic. Create three distinct email templates for the following topics:
"Service Pricing"
"Product Demo"
"General Question"
Personalization:
The greeting of each email must be personalized using the lead's first_name.
The subject line should be dynamic, incorporating the specific inquiry_topic.
Tracking: To prevent sending duplicate emails, the script must track which leads have already been contacted. After successfully sending an email, it should record the lead_id in a separate file named sent_leads.txt.
Configuration: The script should have a clear section at the top for configuration, including placeholders for SMTP server details (host, port) and email credentials (username, app password).
Could you provide a complete Python script that accomplishes this?