Google blocks normal SMTP login for security.
Here’s the clean, safe way to make your ADK newsletter send email through Gmail.
Go to:
https://myaccount.google.com/security
Enable:
✔ 2-Step Verification (You cannot create an app password without this.)
Go to:
https://myaccount.google.com/apppasswords
Choose:
- App: Mail
- Device: Other → type something like
AI Newsletter
Click Generate → you get a 16-character password like:
abcd efgh ijkl mnop
THIS is what you’ll use as SMTP_PASS.
In your project root (newsletter-team/.env):
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=yourgmail@gmail.com
SMTP_PASS=your_app_password_here
NEWSLETTER_FROM_EMAIL=yourgmail@gmail.comReplace your send_newsletter_email in agent.py with this:
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_newsletter_email(to_email: str, subject: str, html: str) -> dict:
"""
Send HTML email via Gmail SMTP.
Requires:
SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, NEWSLETTER_FROM_EMAIL
"""
host = os.getenv("SMTP_HOST")
port = int(os.getenv("SMTP_PORT", "587"))
user = os.getenv("SMTP_USER")
password = os.getenv("SMTP_PASS")
from_email = os.getenv("NEWSLETTER_FROM_EMAIL", user)
if not all([host, port, user, password, from_email]):
raise RuntimeError("SMTP config missing; check .env")
msg = MIMEMultipart("alternative")
msg["Subject"] = subject
msg["From"] = from_email
msg["To"] = to_email
# Text fallback and HTML body
msg.attach(MIMEText("Your email client does not support HTML.", "plain"))
msg.attach(MIMEText(html, "html"))
with smtplib.SMTP(host, port) as server:
server.starttls()
server.login(user, password) # IMPORTANT: use app password
server.sendmail(from_email, [to_email], msg.as_string())
return {"status": "sent", "message_id": "gmail-smtp"}adk webThen in the UI:
I’m a DS, my email is yourgmail@gmail.com. Generate today’s newsletter.
Check your inbox (or spam). Gmail usually delivers instantly.
- They work only for SMTP / IMAP
- They can be revoked anytime
- They don’t expose your real password
Google will block it and may lock your account temporarily.
Use SendGrid / Mailgun / SES — Gmail SMTP has rate limits (100–150/day).