How to Beginner · 3 min read

How to prompt AI for email writing

Quick answer
To prompt AI for email writing, use clear instructions specifying the email's purpose, tone, and audience within your prompt. For example, ask gpt-4o to "Write a professional follow-up email to a client thanking them for their time."

PREREQUISITES

  • Python 3.8+
  • OpenAI API key (free tier works)
  • pip install openai>=1.0

Setup

Install the openai Python package and set your API key as an environment variable for secure access.

bash
pip install openai>=1.0

Step by step

Use the gpt-4o model with a clear prompt describing the email type, tone, and recipient. Below is a complete example that generates a professional follow-up email.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

prompt = (
    "Write a professional follow-up email to a client thanking them for their time and expressing eagerness to continue the conversation. "
    "Keep the tone polite and concise."
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": prompt}]
)

print(response.choices[0].message.content)
output
Subject: Thank You for Your Time

Dear [Client's Name],

I wanted to thank you for taking the time to meet with me. I appreciate the opportunity to discuss how we can work together and look forward to continuing our conversation.

Please feel free to reach out if you have any questions or need further information.

Best regards,
[Your Name]

Common variations

You can customize prompts for different email types (e.g., apology, invitation) or tones (formal, casual). Use other models like claude-3-5-sonnet-20241022 for more creative styles or enable streaming for real-time output.

python
import os
import anthropic

client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

system_prompt = "You are a helpful assistant that writes professional emails."
user_prompt = (
    "Write a casual invitation email to a colleague for a team lunch next Friday at noon."
)

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=300,
    system=system_prompt,
    messages=[{"role": "user", "content": user_prompt}]
)

print(message.content[0].text)
output
Subject: Team Lunch Invitation

Hi [Colleague's Name],

I hope you're doing well! We're planning a team lunch next Friday at noon and would love for you to join us. It'll be a great chance to relax and catch up.

Let me know if you can make it!

Cheers,
[Your Name]

Troubleshooting

If the AI output is too vague or off-topic, refine your prompt by adding more context or specifying the email's purpose and tone. If you get errors, verify your API key is set correctly in os.environ and that you are using the correct model name.

Key Takeaways

  • Specify the email's purpose, tone, and audience clearly in your prompt for best results.
  • Use the gpt-4o model with the OpenAI SDK v1+ pattern for reliable email generation.
  • Customize prompts for different email types and tones to suit your communication needs.
Verified 2026-04 · gpt-4o, claude-3-5-sonnet-20241022
Verify ↗