This Python script automates the process of sending personalized emails (with file attachments) using Gmail's SMTP server. It's perfect for small batch email campaigns, notifications, or simple mailing systems.
- β Secure login using credentials stored in a text file
- β Send emails to a list of recipients from a CSV file
- β Supports file attachments (PDF, images, documents, etc.)
- β Modular, readable code structure
- β Easily customizable subject and message body
Automate_Email/
βββ email_sender.py
βββ credentials.txt
βββ emails.csv
βββ sample.pdf
βββ README.md
-
Install Python if not already installed.
-
Create a Gmail App Password (required if you have 2FA enabled):
- Visit: https://myaccount.google.com/apppasswords
- Login to your account and provide an app name. (e.g.,
automate_mail) - Copy the 16-digit code and store it in
credentials.txtwithout spaces.
-
Prepare Required Files:
-
credentials.txt:
your_email@gmail.com your_app_password_here -
emails.csv:
recipient1@example.com recipient2@example.com recipient3@example.com -
Place the file you want to attach (e.g.,
sample.pdf) in the same directory.
-
-
Run the Script:
python automate_email.py