An Auto Emailer for ACBM designed to automate the process of sending emails with unique attachments (e.g., certificates) to a list of recipients.
The main purpose of this tool is to send bulk emails where each email is customized with a specific attachment (usually an image or document) intended for a specific recipient. It matches files from a local directory to a list of students/recipients provided in an Excel sheet.
Ensure you have Python 3.9 or higher installed.
You will also need a valid Gmail account to use as the sender, with "Less Secure Apps" access enabled or an App Password generated if 2-Factor Authentication is on.
- Clone the repository.
- Install the required Python packages:
pip install pandas openpyxlNote: smtplib and email are part of the Python standard library.
The application is controlled via the config.json file. You must configure this file before running the script.
{
"email": "[your email]",
"password": "[your password]",
"subject": "Email Subject Line",
"body": "body.txt",
"data": "students.xlsx",
"folder": "certificates/",
"files": [
{
"type": "images",
"extension": ".jpg"
}
]
}- email: Your Gmail address.
- password: Your Gmail password (or App Password).
- subject: The subject line for the emails.
- body: The filename of the text file containing the email body content (e.g.,
body.txt). - data: The filename of the Excel file containing recipient data (e.g.,
students.xlsx). - folder: The directory containing the files to be attached (e.g.,
certificates/). - files: A list of file types to scan for.
- type: An arbitrary name for the file type (used internally for column mapping).
- extension: The file extension to look for (e.g.,
.jpg,.pdf).
-
Recipients Excel (
students.xlsx):- Must contain a sheet with at least two columns:
NameandEmail. - The script reads these columns to personalize the email and send it.
- Must contain a sheet with at least two columns:
-
Attachments (
folder):- Place all files to be attached in the directory specified by
folderinconfig.json. - Important: The script assigns files to students based on the numerical order of the filenames.
- Example:
1.jpgwill be sent to the 1st student in the Excel sheet.2.jpgwill be sent to the 2nd student, and so on.
- Ensure your filenames are named sequentially (e.g.,
1.jpg,2.jpg,3.jpg) and correspond to the row order in your Excel file.
- Place all files to be attached in the directory specified by
-
Email Body (
body.txt):- Edit
body.txtto contain the plain text message you want to send.
- Edit
To run the auto-mailer:
python auto-mailer.pyThe script will:
- Load the configuration.
- Read the recipient list.
- Scan the attachment folder and map files to recipients.
- Log in to the SMTP server.
- Iterate through the list and send each email with its corresponding attachment.
- SMTP Authentication Error: If you see an authentication error, check if your email and password are correct. If using Gmail, you likely need to generate an App Password.
- FileNotFoundError: Ensure all paths in
config.jsonare correct and relative to the script's location. - Attachment Mismatch: Verify that the number of files in the folder matches the number of students and that the filenames are numbered correctly to match the Excel row order.