Skip to content

A python script that use gmail and csv file to send email to lists

License

Notifications You must be signed in to change notification settings

pyagmail/pyagmail

Repository files navigation

pyagmail

A python script that use gmail and csv file to send email to lists

┏━┓╋╋╋╋╋╋╋╋╋╋╋╋┏┓
┃╋┣┳┳━┓┏━┳━━┳━┓┣╋┓
┃┏┫┃┃╋┗┫╋┃┃┃┃╋┗┫┃┗┓
┗┛┣┓┣━━╋┓┣┻┻┻━━┻┻━┛
╋╋┗━┛╋╋┗━┛

Prerequisites

You need to allow the sender gmail account to use unsecure app via:

https://support.google.com/cloudidentity/answer/6260879?hl=en

Or setup the script and yagmail to use OAuth2 autorization:

https://yagmail.readthedocs.io/en/latest/setup.html#installing-from-pypi

(maibe) Build animation package

Usage

Works with python 2.7, not tested with python3.

The scripts require some pyton packages (pip install package-name):

Start the script

  • Create a email-list.csv file

In this file, will be read the email list to which to send the emails, for each line a different email, the script will scan this file, line by line, and send the emails to each address read. the first line of the file is not read by the script (you can name as you wish, remember to put the same name into config.py file and put in the same path of the project and use .csv extension).

  • Create a filename-of-the-body.txt file:

This file contain the body of the email you need to use the right encode.

For me, the solution of using a txt file worked well, in the sense that for special characters I didn't have to make any changes for the encoding problems, the example txt file is the original one, without modifications, that I used for send emails, I use the plain text format and not the HTML format, which I have not tested yet.

This file contain the body of the email you need to use the right encode, to be read correctly by the python interpreter, in this file there are some reference links and documentation to understand the problem (you can name as you wish, remember to put the same name into config.py file and put in the same path of the project and use .txt extension).

  • Edit the file config.py all entered values must be contained in quotes '' (apart timer field, it don't need '') :
email = {'subject': 'Put here the email subject',
        'body': 'filename-of-the-body.txt',
        'email': 'sender.email@gmail.com',
        'passwd': 'SenderPassword',
        'timer': 100,
        'file': 'email-list.csv',
        'log_email': 'log.email.receiver@gmail.com'}

The timer field is the time expressed in seconds between sending an email and the other, the value 100 is about 2 minutes.

  • Run for 1 time the keyring-registration.py file set the same password of your sender email password:
python keyring-registration.py

This will store into linux keyring system the yagmail autorization to use and run the machine.

  • Run the pyagmail.py script to start sending mail:
python pyagmail.py

launching the script you will need to leave the terminal window open to complete it, otherwise it will stop.

Since, depending on the length of the list, the execution of the script may take days, to overcome the problem of keeping the terminal open, if you use linux, you can take advantage of tmux to launch the script in the background:

Some solution to run in background with windows:

To Do

  • Loading ideas...
  • Build setup file
  • Implementing OAut2 for gmail secure apps
  • Made plain and html version of the emails
  • Set digital signature to emails in gmail
  • Adding animation when script is runnig
  • Configuring keyring
  • Set google account to operate with in less security apps (google account option option security)
  • Set autoreply message in gmail to tell users where can contact you (using gmail account settings to do this)

Used resouces

Usefull resources:

Gmail stats

To do

  • Loading...
┏━━┳┓╋╋╋╋╋╋┏┓┏━┓
┗┓┏┫┗┳━┓┏━┳┫┣┫━┫
╋┃┃┃┃┃╋┗┫┃┃┃━╋━┃
╋┗┛┗┻┻━━┻┻━┻┻┻━┛

┏━━━┓
┃┏━━┛
┃┗━━┳━━┳━┓┏┓┏┳━━┳┳━┓┏━━┓
┃┏━━┫┏┓┃┏┛┃┃┃┃━━╋┫┏┓┫┏┓┃
┃┃╋╋┃┗┛┃┃╋┃┗┛┣━━┃┃┃┃┃┗┛┃
┗┛╋╋┗━━┻┛╋┗━━┻━━┻┻┛┗┻━┓┃
╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋┏━┛┃
╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋╋┗━━┛

┏━┓╋╋╋╋╋╋╋╋╋╋╋╋┏┓
┃╋┣┳┳━┓┏━┳━━┳━┓┣╋┓
┃┏┫┃┃╋┗┫╋┃┃┃┃╋┗┫┃┗┓
┗┛┣┓┣━━╋┓┣┻┻┻━━┻┻━┛
╋╋┗━┛╋╋┗━┛

Releases

No releases published

Packages

No packages published