This script is used to send email to a list of email addresses.
-
Support declaring email account information used to send email through config.ini file. No need to edit the configuration line by line in the script.
-
Declare a simple email list of recipients through the files emails.txt.
-
Support sending email with HTML format and email content specified in message.html file. This makes your emails look nicer and more informative, instead of sending a single line of text.
-
Support logging to email.log file so that you know the execution results of the script.
-
Supports SMTP connection with both port 25, 465 and 587. Very suitable when you use with different SMTP servers.
Open the config.ini file and change the values to yours.
Open the emails.txt file and change it to your list of email recipients.
Some note:
- Each line in the file is an email address.
- There should be no extra spaces in the email address line.
- There should be no blank lines in the file.
- You should process the list before putting in this file.
Open file message.html and edit the file content to the email you want to send. You will need to know a little bit of HTML and CSS to make changes here. Or you can use templates available on the internet or tools that support automatic HTML template generation.
You open file send-email.py, at line 80, you change the subject content of the email you want to send.
...
# Subject
subject = "Sample email from Python3"
...
Run the command below to send the email.
./send-email.py
The log of the script should look like this, you can open the email.log file and see.
2023-01-29 11:41:31,148 INFO: Start sending email
2023-01-29 11:41:31,149 INFO: Reading SMTP configurations from config.ini
2023-01-29 11:41:31,149 INFO: Finished reading SMTP configurations
2023-01-29 11:41:37,095 INFO: Email sent to [email protected]
2023-01-29 11:41:41,405 INFO: Email sent to [email protected]
2023-01-29 11:41:41,406 INFO: Finished sending email
Recipient email results.
Software | Version |
---|---|
Python | 3.8.10 |