Author: Nicolás Bruno
email: nicobruno92@gmail.com
repository: https://github.com/Nicobruno92/certification_automatization
This repository contains scripts to automate the process of creating and sending certificates to participants of courses and conferences. The system handles:
- Creating personalized certificates with participant names
- Sending personalized emails with attached certificates
- Managing batches of certificates for different types of participants (attendees, presenters, etc.)
Libraries to have installed:
- pillow - For image manipulation and certificate creation
- pandas - For handling data from spreadsheets
- email - For email composition and sending
The utility functions are in utils.py which must be in the same folder as the main scripts.
The utils.py file contains several key functions:
from utils import send_mail, eliminate_accents, certificate_maker
import pandas as pd-
certificate_maker() - Creates personalized certificates
- Takes a certificate template image and adds a participant's name
- Handles formatting, text positioning, and color
- Saves the certificate as a PDF file
-
send_mail() - Sends emails with optional attachments
- Handles SMTP connection and email composition
- Supports HTML content for rich email formatting
- Attaches certificates to emails
-
eliminate_accents() - Normalizes text by removing accents from characters
- Used for filename consistency
-
font_size_by_name() - Adjusts font size based on name length
- Ensures names fit properly on certificate templates
This Jupyter notebook demonstrates the basic workflow for creating and sending certificates. It's an interactive way to understand the core functionality.
- Open the notebook in Jupyter
- Execute each cell sequentially
- Customize parameters as needed
- Test with a single certificate before sending to all participants
This script creates certificates for event attendees/assistants.
How to use:
python create_assistant_certificates.pyConfiguration needed:
- Modify the script to point to your attendee list (Excel/CSV)
- Set the certificate template path
- Configure the text position, font, and colors
- Define output directory for saving certificates
This script creates certificates for presenters at your event.
How to use:
python create_exposition_certificates.pyConfiguration needed:
- Update the presenter list path
- Set the appropriate certificate template
- Adjust text formatting (may differ from attendee certificates)
- Define output directory
This script sends certificates to event attendees via email.
How to use:
# Test SMTP connection only
python send_certificates_asistentes.py --test
# Test email to a specific address
python send_certificates_asistentes.py --test your.email@example.com
# Send certificates to all attendees
python send_certificates_asistentes.pyConfiguration required:
- Create a
config_gmail.pyfile with your email settings:# config_gmail.py example EMAIL_USER = "your.email@gmail.com" EMAIL_PASSWORD = "your-app-password" # Use app password for Gmail EMAIL_FROM = "Your Name <your.email@gmail.com>" REPLY_TO = "support@yourorganization.com" SMTP_SERVER = "smtp.gmail.com" SMTP_PORT = 587 DOMAIN = "yourorganization.com"
- Create an
email_template_asistentes.pyfile with your email content:# email_template_asistentes.py example SUBJECT = "Your Certificate for [Event Name]" BODY = """ <html> <body> <p>Hello {attendee_name},</p> <p>Thank you for attending our event. Your certificate is attached.</p> <p>Best regards,<br>Event Team</p> </body> </html> """
- Ensure certificates are generated and placed in the
certificates_dirpath specified in the script
This script sends certificates to event presenters.
How to use:
# Same options as the attendee version
python send_certificates_presentations.py [options]Configuration:
- Similar to the attendee version but may use different email templates and certificate paths
- Create appropriate config and template files as described above
Set the path to the folder containing the necessary files such as:
- the certificate template (always in jpg)
- the student list
- font file (if necessary)
- folder to save the certificates
- etc
folder_path = "Automatization Example/"
list_path = folder_path + "lista_alumnos.xlsx"
certificate_folder = folder_path + "Certificates/"
certificate_template = folder_path + "certificate_template.jpg"
font_file = folder_path + "D-DIN-Bold.ttf" # an example of an special fontSet the name of the columns with student first name, last name and email
student_list = pd.read_excel(list_path) # read excel files
# sudent_list = pd.read_csv(list_path) #read csv files
email = "mail"
first_name = "Nombre"
last_name = "Apellido"- Location of the name on the template
- Color of the text
- Size of the text
- Fonts
- etc
Finally makes a certificate to see if it's ok
# NT colors
grey = "#21201F"
green = "#9AC529"
lblue = "#42B9B2"
pink = "#DE237B"
orange = "#F38A31"
text_color = grey
location_text = (810, 470)
font_size = 63# example certificate
certificate_maker(
certificate_template=certificate_template,
student_name="Juan Pérez",
text_color=text_color,
location_text=location_text,
font_name=font_file,
text_size=font_size,
save_path=certificate_folder,
)For this it is important to use a throwaway email. Because security parameters will complicate everything
subject = "Test email automatization of certificates"
sender_email = "noreply.neurotransmitiendo@gmail.com"
password = input("Type your password and press enter: ")What it is in {} is what is going to be replaced afterwards by the name inside the loop function in order to personalize it.
The text is in HTML.
- In order to end a paragraph add a break "<br>"
- <b> - Bold text
- <strong> - Important text
- <i> - Italic text
- <em> - Emphasized text
- <mark> - Marked text
- <del>
- Deleted text - <ins> - Inserted text
- <sub> - Subscript text
- <sup> - Superscript text
To adapt this system for your own event:
-
Prepare Your Data:
- Create an Excel/CSV file with participant information (name, email, etc.)
- Design your certificate template as a JPG image
- Choose appropriate fonts
-
Configure Scripts:
- Update file paths to point to your data and template files
- Adjust certificate text position and styling
- Customize email templates
-
Test Thoroughly:
- Generate sample certificates to check layout and formatting
- Send test emails to yourself before mass sending
- Verify that all certificates are correctly personalized
-
Execute:
- Run certificate creation scripts first
- Verify all certificates were created correctly
- Run sending scripts with appropriate options
To run the certificate creation and mailing process with the basic workflow:
- Set up your data file (Excel or CSV) with participant information
- Configure the certificate template and parameters
- Test a single certificate generation to verify layout
- Run the full process with:
for index, row in student_list.iterrows():
# Information from the list
receiver_email = row[email]
full_name = row[first_name] + " " + row[last_name]
# Makes the certificate
certificate_maker(
certificate_template=certificate_template,
student_name=full_name,
text_color=text_color,
location_text=location_text,
font_name=font_file,
text_size=font_size,
save_path=certificate_folder,
)
# Prepares email
body_formatted = body.format(name=row[first_name])
attachment = (
certificate_folder + "certificado_" + eliminate_accents(full_name) + ".pdf"
)
# send the email, good luck!
send_mail(
sender_email=sender_email,
receiver_email=receiver_email,
password=password,
subject=subject,
body=body_formatted,
attachment=attachment,
)- Email Sending Failures: Verify your SMTP settings and ensure you're using an app password for Gmail
- Certificate Formatting Issues: Adjust text position and font size based on your template
- Filename Errors: Check that the
eliminate_accents()function correctly handles special characters in names - Missing Attachments: Ensure certificates are being generated with correct names before sending
Always double-check your email list and certificate templates before sending certificates to all participants. Once emails are sent, they cannot be recalled.