This repository is for practicing sending email with python.
- Python 3 (only the standard library is used — nothing to install)
- A Gmail account with 2-Step Verification enabled and an app password generated for it
Three environment variables are read at startup. If any is missing, the program prints which one and exits with status 1 before any connection is attempted.
| Variable | Description |
|---|---|
EMAIL_SENDER_ADDRESS |
The Gmail address the message is sent from |
EMAIL_SENDER_APP_PASSWORD |
The 16-character app password for that account — not the account password |
EMAIL_RECIPIENT |
The address the message is sent to |
export EMAIL_SENDER_ADDRESS="you@gmail.com"
export EMAIL_SENDER_APP_PASSWORD="abcdefghijklmnop"
export EMAIL_RECIPIENT="someone@example.com"./run.shOr without the wrapper script:
python3 src/main.pyEither way the following prompt appears:
Use SSL or TLS? (s/t):
s— connects tosmtp.gmail.com:465over SSLt— connects tosmtp.gmail.com:587and upgrades the connection with STARTTLS- Anything else — prints
Invalid input! Please type 's' or 't'.and exits without connecting
Both answers log in to Gmail and send a real email containing one randomly chosen message from the list in src/main.py.
If the send fails — an unreachable server, a rejected login, a refused recipient — the reason is printed as Failed to send email: <reason> and the program exits with status 1, so run.sh reports the failure rather than a success.
The test suite uses the standard library's unittest module and mocks every SMTP
connection, so running it sends no email and opens no socket. From the repository root:
python3 -m unittest discover -s tests -t .