Prompt
How to send email from Python
Latest observation
Aug 13, 2026 · OpenAI APIWeb search: off
You can send email from Python using the built-in smtplib library.
Basic example
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg["Subject"] = "Test email"
msg["From"] = "you@example.com"
msg["To"] = "recipient@example.com"
msg.set_content("Hello, this is a test email from Python.")
with smtplib.SMTP("smtp.example.com", 587) as smtp:
smtp.starttls()
smtp.login("you@example.com", "your_password")
smtp.send_message(msg)
print("Email sent!")
How it works
SMTP(...)connects to your mail serverstarttls()secures the connectionlogin()authenticates yousend_message()sends the email
For Gmail
If you're using Gmail:
- SMTP server:
smtp.gmail.com - Port:
587 - You may need an App Password instead of your normal password if 2-factor authentication is enabled.
Example:
with smtplib.SMTP("smtp.gmail.com", 587) as smtp:
smtp.starttls()
smtp.login("yourgmail@gmail.com", "your_app_password")
smtp.send_message(msg)
If you want HTML email
msg.set_content("This is the plain text version.")
msg.add_alternative("""
<html>
<body>
<h1>Hello</h1>
<p>This is an <b>HTML</b> email.</p>
</body>
</html>
""", subtype="html")
If you want, I can also show:
- sending attachments
- sending email through Gmail/Outlook
- using
yagmailorsmtplibwith a full working script
Observation history
Unlock observation history
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.