This script allows you to send emails to multiple recipients using SMTP with a Gmail account. It reads email addresses from a specified database file and the email content from another file.
- Reads unique recipient email addresses from a file.
- Reads email content from a separate file.
- Sends emails via Gmail SMTP.
- Handles exceptions for missing files and email sending errors.
- Prompts the user for confirmation before sending emails.
Ensure you have Python installed and install the required dependencies using:
pip install -r requirements.txtMake sure to enable "Less Secure Apps" or use an App Password for authentication if needed.
- Clone or download this script.
- Ensure you have a
user_login.pyfile that contains the following:email = "your_email@gmail.com" password_key = "your_email_password_key"
- Create a text file (e.g.,
database.txt) with recipient email addresses (one per line). Duplicate addresses will be removed automatically. - Create another text file (e.g.,
content.txt) with the message body. - Install dependencies:
pip install -r requirements.txt
Run the script from the terminal:
python main.py <database_file> <content_file>Example:
python main.py database.txt content.txtBefore sending emails, the script will prompt for confirmation.
read_recipients(file_path): Reads recipient emails from a file, ensuring uniqueness.read_content(file_path): Reads and returns the content of a file as a string.send_email(recipients, content, subject): Sends an email to the recipients.main(): Handles command-line arguments, reads files, and confirms before sending emails.
- If a file is missing, an error message is displayed, and the script exits.
- If sending an email fails, an error message is printed with the recipient's email.
Do not store sensitive credentials in plain text. Use environment variables or a secure secrets manager.
This script is provided "as is" without warranty. Use at your own risk.
Daniels Stulpe