Skip to content

Python script used to send email to a list of email addresses

License

Notifications You must be signed in to change notification settings

dungpham91/python-send-email-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python3 script to send email to list

This script is used to send email to a list of email addresses.

Table of contents

1. Features

  • 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.

2. Usage

Step 1: Change SMTP configuration

Open the config.ini file and change the values to yours.

Step 2: Change recipient list

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.

Step 3: Edit email content

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.

Step 4: Change the Subject of the email

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"
...

Step 5: Run the script

Run the command below to send the email.

./send-email.py

3. Result

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.

email.jpg

4. Software version

Software Version
Python 3.8.10

About

Python script used to send email to a list of email addresses

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published