This Python script allows you to send HTML-formatted emails using Gmailβs SMTP server. It supports secure login with TLS encryption, App Passwords, and uses MIME multipart messages for rich content.
- β Connects securely to Gmail via TLS
- β Uses App Password for authentication (Gmail 2FA-compatible)
- β Sends rich HTML emails
- β Supports Cc and Bcc headers
- β Clean error handling and debug output
π SMTP/ βββ mail.html # HTML email template βββ html_mail.py # for html content mail βββ README.md # This file |__ text_mail.py # for only text mails
Gmail blocks less secure apps by default. You must enable 2FA and use an App Password.
- Go to https://myaccount.google.com/security
- Enable 2-Step Verification
- Go to https://myaccount.google.com/apppasswords
- Create an App Password (Select βMailβ > βOtherβ > "Python SMTP")
git clone https://github.com/your-username/smtp-email-sender.git cd SMTP
- Create an mail.html file (or use the sample provided)
This is a test email sent using Python + Gmail SMTP.
- Run the script
python html_email.py
Youβll be prompted to enter your App Password securely.
π‘οΈ Security Notes Never hardcode passwords β use getpass or environment variables.
Donβt commit your mail.html with sensitive content unless itβs just a template.
This script is for educational and ethical use only.
βοΈ Author Godson Mug1sha (aka KINGπ) Cybersecurity Student | Python Dev | Email Hacker (ethical) π Kigali, Rwanda
π§ Future Improvements Add attachments support
Support for inline images
Switch to OAuth2 (no App Passwords)
GUI version with Tkinter or Electron