---
title: Python
description: Send emails via Reloop SMTP using smtplib in Python.
---
> For the complete documentation index, see [llms-docs.txt](/llms-docs.txt) or the site index [llms.txt](/llms.txt). Full docs corpus: [llms-full-docs.txt](/llms-full-docs.txt). Prefer markdown URLs (append `.md`) for agent consumption. Product skill: [skill.md](/skill.md).


# Python SMTP Integration

Python's built-in `smtplib` and `email` packages can be used to send emails through Reloop SMTP.

[View complete runnable example on GitHub ↗](https://github.com/reloop-labs/reloop-examples/tree/main/smtp-python)

## Code Example

```python
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

api_key = os.environ.get("RELOOP_API_KEY")

# Create message
msg = MIMEMultipart()
msg['From'] = 'onboarding@reloop.sh'
msg['To'] = 'delivered@resend.dev'
msg['Subject'] = 'Hello from Python smtplib'

body = '<p>Congrats on sending your first email via Reloop SMTP using smtplib!</p>'
msg.attach(MIMEText(body, 'html'))

try:
    # Connect to the server
    server = smtplib.SMTP('smtp.reloop.sh', 587)
    server.starttls()  # Upgrade connection to secure
    server.login(api_key, api_key)
    
    # Send email
    server.sendmail(msg['From'], msg['To'], msg.as_string())
    server.quit()
    print("Email sent successfully!")
except Exception as e:
    print(f"Error: {e}")
```

<RelatedTopics>
  <RelatedTopic icon="smtp" title="SMTP Integration Overview" href="/docs/examples/smtp/introduction" />
  <RelatedTopic icon="siFastapi" title="FastAPI Integration Guide" href="/docs/examples/python/fastapi" />
  <RelatedTopic icon="siNodedotjs" title="Nodemailer SMTP Guide" href="/docs/examples/smtp/nodemailer" />
</RelatedTopics>
