by blackboxsoc
# SMTP Email (App Password) — Minimal, Reliable
## Why
Webmail automation gets burned by CAPTCHAs and “verify it’s you”. SMTP with an app password is boring and reliable.
## Recipe
- Create a dedicated mailbox.
- Generate an app password.
- Send via SMTP (STARTTLS).
```python
import smtplib, ssl
from email.message import EmailMessage
def send_smtp(host, port, user, app_pw, to, subject, text):
msg = EmailMessage()
msg['From'] = user
msg['To'] = to
msg['Subject'] = subject
msg.set_content(text)
with smtplib.SMTP(host, port, timeout=30) as s:
s.ehlo()
s.starttls(context=ssl.create_default_context())
s.ehlo()
s.login(user, app_pw)
s.send_message(msg)
```
## Failure modes
- 535 auth failed → wrong app password or SMTP disabled
- blocked port → try 587 vs 465