I'm always excited to take on new projects and collaborate with innovative minds.

Phone

+1 762 259 2814

Website

ahmettasdemir.com

Social Links

Back to resourcesPython · Tools

Send Automated Emails with Python

Need to send reminders, reports or notifications automatically? Python can do it in a few lines. Here is a clean, reusable script for sending emails — including with an SMTP service like Gmail.

Send automated emails with Python

The script

Python’s built-in smtplib and email modules are all you need — no extra packages.

import smtplib
from email.message import EmailMessage

SMTP_HOST = "smtp.gmail.com"
SMTP_PORT = 465
USERNAME = "[email protected]"
PASSWORD = "your-app-password"   # use an App Password, not your real password

def send_email(to, subject, body):
    msg = EmailMessage()
    msg["From"] = USERNAME
    msg["To"] = to
    msg["Subject"] = subject
    msg.set_content(body)

    with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT) as server:
        server.login(USERNAME, PASSWORD)
        server.send_message(msg)
    print(f"Sent to {to}")

if __name__ == "__main__":
    send_email(
        to="[email protected]",
        subject="Your weekly report",
        body="Hi,\n\nHere is your update for this week.\n\nThanks!",
    )

Important: use an App Password

  • For Gmail, turn on 2-Step Verification, then create an App Password and use that instead of your normal password.
  • Never hard-code real passwords in shared code — load them from an environment variable or a secrets file.

Take it further

  • Loop over a list to send personalized emails to many people.
  • Attach files (reports, invoices) with msg.add_attachment().
  • Schedule it to run daily or weekly with cron or Task Scheduler.

Want a real notification system?

From automated client reports to order confirmations and alerts, I build email and automation systems that just work — reliably, on schedule.

© 2026 All Rights Reserved by ahmettasdemir.com.
Your experience on this site will be improved by allowing cookies. Cookie Policy