A client to send emails to multiple directions programatically using Python
- Go into this link and click the button that reads "ENABLE THE GMAIL API", making sure to enter with the gmail account from which all the mails will be sent (this will create a project inside your google console, you want to remember the name. You can also change its name to your convenience).
- Click the button that reads "DOWNLOAD CLIENT CONFIGURATION" and move the downloaded file to the root of this repository. Make sure that the file is named client_secret.json.
- Inside the file parameters.py, replace the content of the variable MAIL_SENDER with the name of the gmail account from which all the mails will be sent and comment the last 2 lines.
- Run the following command:
python3 setup.py
- If that mail is being used for the first time, a browser will open asking for permission to use extraordinary data from that Google Account. Agree to everything. It is possible that the browser blocks the connection thinking that it is fraudulent, in which case the browser should be gracefully ingnored.
- If that mail had already been used, no browser will open. Either way, a mail will be sent to the account by itself.
- The script requires a file called mail_list.csv containing data of every target.
- The script requires a file called template.txt which is a template for the mail which is going to be sent. The template can use each of the target's name, last name, mail or enterprise inside the body just placing, for example, {name} where you want the name to appear.
- The repository contains a sample_mail_list.csv file and a sample_template.txt file for you to modify. Note that the file names MUST be mail_list.csv and template.txt.
- The script won't work without the setup being completed and the file client_secret.json being in the repository.
- If you want to send attachments, you must put them in a folder inside the root of the repository named attachments.
Once the setup is completed and every required file is added, to run the script all that is left is to run:
python3 main.py title
Where title
will be the subject of the mails sent. Note that if title
is ommited, the subject will be 'Sample Diffusion'.
You can also change most of the naming requirements inside the parameters.py file if you want to do so.
- The column which contains the mails to send the emails MUST be called
mail
by default, but it can be changed within parameters.py to match the specific database. - The csv format can be changed within parameters.py by changing the value
DELIMITER
for the separator andSKIPINITIALSPACE
to specify an initial space after each delimiter.