A Python tool that takes any email body and generates five subject line variations in different tones — professional, friendly, urgent, and curiosity-driven — using Gemini.
Get a free key from Google AI Studio and configure the SDK.
pip install google-generativeai
import google.generativeai as genai
import os
genai.configure(api_key=os.environ.get('GEMINI_API_KEY') or 'your-api-key-here')
model = genai.GenerativeModel('gemini-1.5-flash')
# Quick test
r = model.generate_content("Say hello in 5 words.")
print(r.text)
Prompt Gemini to write subject lines in five distinct tones.
def generate_subjects(email_body):
prompt = f"""You are an email marketing expert.
Read the email body below and generate exactly 5 subject lines — one for each of these tones:
1. Professional / Formal
2. Friendly / Conversational
3. Urgent / Time-sensitive
4. Curiosity-driven / Intriguing
5. Direct / Clear benefit
Format your response EXACTLY like this:
1. [Professional]: subject here
2. [Friendly]: subject here
3. [Urgent]: subject here
4. [Curiosity]: subject here
5. [Direct]: subject here
Email body:
{email_body}"""
response = model.generate_content(prompt)
return response.text
email = """
Hi team,
I wanted to let you know that we have redesigned our onboarding process.
New users can now complete setup in under 5 minutes instead of 30.
The new flow includes video guides, tooltips, and a progress checklist.
Please review the attached document and share your feedback by Friday.
Thanks,
Sarah
"""
print(generate_subjects(email))
1. [Professional]: New Onboarding Process: Review Required by Friday 2. [Friendly]: We've made onboarding way easier — check it out! 3. [Urgent]: Action Required: Onboarding Review Due This Friday 4. [Curiosity]: What if new users could be fully set up in 5 minutes? 5. [Direct]: New 5-Minute Onboarding Flow — Your Feedback Needed
Build a loop so users can paste emails and instantly get subjects.
def main():
print("AI Email Subject Generator (powered by Gemini)")
print("Paste your email body below. Type DONE on a new line when finished.\n")
while True:
lines = []
while True:
line = input()
if line.strip() == 'DONE': break
lines.append(line)
body = '\n'.join(lines).strip()
if not body:
print("No email content — exiting."); break
print("\nGenerating subject lines...\n")
result = generate_subjects(body)
print(result)
print("\n" + "="*50)
print("Generate for another email? (paste it, or press Ctrl+C to exit)\n")
main()
A 40-line tool that could save hours of email copywriting every week. The same pattern — describe the task in natural language, specify the output format, parse the response — works for product descriptions, SEO meta tags, ad copy, and any other text generation task.
Spotted a bug, broken code, or something that doesn't look right? Tell us what's off and we'll fix it.