This script automates the process of sending batch emails using SMTP. It retrieves recipient email addresses from an Excel file, filters them based on specific criteria, and sends emails in batches to avoid SMTP limits.
- The script reads email addresses from an Excel file.
- It filters recipients where the "Status" column is marked as "YES".
- It sends emails in BCC to recipients in batches of 100 to avoid SMTP limits.
- The script authenticates using an App Password for security.
To use this script, you need to provide the following details:
sender_email: Your email address (e.g.,your-email@gmail.com)sender_password: An App Password generated from your Google account (details below)smtp_server: SMTP server (default:smtp.gmail.com)smtp_port: SMTP port (default:587)
recipients: A list of email addresses (fetched from the Excel file)subject: The subject of the emailbody: The main content of the emailbatch_size: The number of recipients per batch (default:100)
Most SMTP servers (including Gmail) impose a limit on the number of recipients per email to prevent spam. The batch size of 100 ensures that the script complies with these limitations while maintaining efficiency. If you have more than 100 recipients, the script will send multiple emails in separate batches.
Since Google restricts direct login via scripts, you must use an App Password:
- Go to Google App Passwords.
- Sign in to your Google account.
- Select Mail as the app and Other (Custom Name) for the device.
- Click Generate, and copy the 16-character password.
- Use this password in the script instead of your regular Gmail password.
- Install dependencies:
pip install pandas openpyxl
- Replace
your-email@gmail.comandyour-app-passwordin the script. - Run the script:
python mail_dispatch.py
- This script is specifically designed for the Mozilla Credits repository.
- Ensure that your Excel file follows the correct format with email addresses and a "Status" column.
- Modify the script if you need a different filtering condition.
For any issues or modifications, please contribute to the Mozilla Credits repo!