A simple Python script to send an HTML email to a list of gyms loaded from a CSV file. It supports a safe "test mode" that prints emails to the console without sending.
- Test mode: Preview recipients, subject, and HTML body without sending
- CSV-driven: Reads
Gymname andContact Emailcolumns - Gmail SMTP: Uses Gmail with an App Password for secure sending
- Python: 3.8+
- Pip: to install dependencies
- Gmail account with 2‑Step Verification and an App Password for SMTP
# (Optional) create and activate a virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependency
pip install python-dotenv- Create a
.envfile in the project root with your Gmail credentials (App Password recommended):
EMAIL_ADDRESS=[email protected]
EMAIL_PASSWORD=your_16_char_app_password- Prepare a CSV with at least these headers:
Gym,Contact Email
Acme Fitness,[email protected]
- Update the CSV path in
send_emails_gyms.py(near the bottom of the file) to point to your CSV. The script currently references an absolute path underDownloads.
- Open
send_emails_gyms.pyand set the mode:TEST_MODE = Trueto preview output only (default)TEST_MODE = Falseto actually send emails
- Optionally customize
subjectandbody_template(HTML allowed). The placeholder{gym_name}will be interpolated from the CSV. - Run the script:
python send_emails_gyms.py- Gmail SMTP: The script uses
smtp.gmail.com:465with SSL. - App Password: Required if your account has 2FA (recommended). Generate one under Google Account → Security → App passwords.
- Rate limits: Gmail has sending limits. The script sleeps 2 seconds between rows; consider increasing for large lists.
- Encoding: CSV is read with
utf-8-sig. Keep header names exact:GymandContact Email.
- Login/auth errors: Ensure you are using an App Password and that
.envvariables are loaded. - Emails not sending, but no error: Check
TEST_MODEis set toFalse. - CSV rows skipped: Ensure both
GymandContact Emailcolumns are present and non-empty.
- Do not commit your
.envfile. - Use an App Password instead of your main Gmail password.