A Python script for sending automated emails at regular intervals using SMTP. The script supports both JSON and CSV formats for recipient data and includes multi-language support for error messages and logs.
automated-email-sender
├── src
│ ├── email-sender.py # Main script for sending automated emails
│ ├── validators.py # Validation logic for environment variables and SMTP configuration
├── data
│ ├── emails.csv # CSV file containing recipient data
│ ├── emails.json # JSON file containing recipient data
├── translations
│ ├── en.json # English translations
│ ├── pt.json # Portuguese translations
├── .env # Environment variables for email configuration
├── requirements.txt # Python dependencies required for the project
├── email_sender.log # Log file for email sending status and errors
├── README.md # Documentation for the project
git clone https://github.com/NunoBentes/automated-email-sender.git
cd automated-email-senderMake sure you have Python installed, then run the following command to install the required dependencies:
pip install -r requirements.txtEdit the .env file in the root directory and add your email credentials and configuration:
# Preferred language for translations (e.g., 'en' for English, 'pt' for Portuguese)
LANGUAGE=pt
# Mode of the email data file: 'json' or 'csv'
EMAIL_MODE=csv
# Path to the CSV file
EMAIL_DATA_CSV=data/emails.csv
# Path to the JSON file
EMAIL_DATA_JSON=data/emails.json
# Interval in seconds between sending emails
SEND_EMAIL_INTERVAL=120
# SMTP server configuration
EMAIL_SMTP=mail.yourdomain.com
EMAIL_SMTP_PORT=587
EMAIL_USE_TLS=true # Use TLS for secure email sending
SENDER_EMAIL[email protected]
SENDER_PASSWORD=your_password
# Sender email credentials
SENDER_NAME=Nuno Bentes
# Email Subject
EMAIL_SUBJECT=Your Email Subject Here
# Email Body Template
EMAIL_BODY="Hello {recipient_name},\n
This is an automated email sent by {sender_name}.
Thank you for being a valued customer.\n
Best regards,
{sender_name}"You can use either a JSON or CSV file to store recipient data.
[
{
"name": "John Doe",
"email": "[email protected]"
},
{
"name": "Jane Smith",
"email": "[email protected]"
},
{
"name": "Alice Johnson",
"email": "[email protected]"
}
]name,email
John Doe,[email protected]
Jane Smith,[email protected]
Alice Johnson,[email protected]
Execute the script to start sending emails:
python src/email-sender.py-
Multi-Language Support:
- Error messages and logs are available in multiple languages (e.g., English and Portuguese). Configure the language in the
.envfile using theLANGUAGEvariable.
- Error messages and logs are available in multiple languages (e.g., English and Portuguese). Configure the language in the
-
Flexible Recipient Data:
- Supports both JSON and CSV formats for recipient data.
-
SMTP Configuration Validation:
- Validates SMTP credentials and connection before sending emails.
-
Logging:
- Logs email sending status and errors to
email_sender.log.
- Logs email sending status and errors to
-
Customizable Email Content:
- Use placeholders like
{recipient_name},{sender_name}, and{date}in the email body template.
- Use placeholders like
Subject: Your Email Subject Here
Body:
Hello Jane Smith,
This is an automated email sent by John Smith.
Thank you for being a valued customer.
Best regards,
John Smith
-
SMTP Authentication Error:
- If you see an error like
(535, b'Incorrect authentication data'), check your SMTP credentials in the.envfile.
- If you see an error like
-
Missing Translation File:
- If a translation file is missing, the script will fall back to English. Ensure the
translationsdirectory containsen.jsonandpt.json.
- If a translation file is missing, the script will fall back to English. Ensure the
-
Email Data File Not Found:
- Ensure the
EMAIL_DATA_CSVorEMAIL_DATA_JSONpath in the.envfile points to an existing file.
- Ensure the
-
Empty Email Data File:
- Ensure the recipient data file is not empty.
The script logs all email sending statuses and errors to email_sender.log. Example log entry:
2025-04-19 16:45:18,630 - INFO - Email enviado com sucesso para [email protected].
This project is licensed under the MIT License. See the LICENSE file for details.
