This Python script automates the process of sending emails to a list of recipients using the SMTP protocol. The script is designed to establish a connection with an SMTP server, create an email message, and send it to multiple recipients.
-
Clone Script Repo:
git clone https://github.com/Mubarak1A/emailSender.git -
Update Email List: Populate the
emailslist in the script with the email addresses of the recipients to whom you want to send emails and that of the sender. -
HTML Content: Customize the content of the HTML email by modifying the
sample.htmlfile. The script reads the content from this file and substitutes a variable (e.g.,name) with a specified value. -
Run the Script: Execute the script using the following command:
python3 send_mail.py
The script follows these key steps:
-
Read HTML Content: The HTML content for the email is read from the
sample.htmlfile using thepathlibmodule. -
Email Configuration: The script configures the email message using the
EmailMessageclass. Sender information, recipient email, and email subject are set. -
SMTP Connection: The script establishes a connection with the SMTP server (in this case, Gmail's SMTP server) using the
smtplibmodule. -
Sending Emails: For each email in the
emailslist, the script sends an email with the configured content. -
Print Status: The script prints a success message for each email sent.
- Python 3
smtplib(standard library)email.message(standard library)string.Template(standard library)pathlib(standard library)
Note: Ensure that the SMTP server specified in the script allows the provided sender email to send emails. Additionally, be cautious when handling sensitive information and consider using secure methods for storing and retrieving credentials.
Feel free to customize the script according to your specific use case and email content requirements.