From f6abda877233b2506e185ce584d5b80020aded3a Mon Sep 17 00:00:00 2001 From: thisfro Date: Sun, 9 Oct 2022 19:11:46 +0200 Subject: [PATCH 1/3] Add ignores --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..11358ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +vars.py +*.csv +message.html +.DS_Store +*.pyc From 0bb4a1d06cfaa1b8c6e7e15f77e3c84a360cfdd3 Mon Sep 17 00:00:00 2001 From: thisfro Date: Sun, 9 Oct 2022 19:14:07 +0200 Subject: [PATCH 2/3] Parameterize everything --- mail.py | 11 ++++++++--- vars.py.example | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mail.py b/mail.py index 4340028..052e633 100644 --- a/mail.py +++ b/mail.py @@ -1,4 +1,5 @@ import smtplib +import time from string import Template @@ -32,7 +33,7 @@ def read_template(filename): def main(): contacts = get_contacts('contacts.csv') - message_template = read_template('message.txt') + message_template = read_template('message.html') # set up the SMTP server s = smtplib.SMTP(HOST, PORT) @@ -41,6 +42,7 @@ def main(): # For each contact, send the email: for i in contacts.index: + print(f"Sending email {i+1}\n") msg = MIMEMultipart() # create a message # add in the actual person name to the message template @@ -48,11 +50,11 @@ def main(): message = message_template.substitute(contact_dict) # Prints out the message body for our sake - print(message) + print(f"{message}\n") # setup the parameters of the message msg['From'] = MY_ADDRESS - msg['To'] = contacts["email"][i] + msg['To'] = contacts[MAIL_COLUMN][i] msg['Subject'] = SUBJECT # add in the message body @@ -62,6 +64,9 @@ def main(): s.send_message(msg) del msg + if (i + 1) % WAIT_EVERY == 0: + time.sleep(DELAY_SEC) + # Terminate the SMTP session and close the connection s.quit() diff --git a/vars.py.example b/vars.py.example index 1904b27..bbd94a3 100644 --- a/vars.py.example +++ b/vars.py.example @@ -1,5 +1,10 @@ +SUBJECT = '' +EMAIL_COLUMN = '' + MY_ADDRESS = 'example@domain.tld' PASSWORD = 'p4ssw0rd' HOST = 'mail.domain.tld' PORT = 587 -SUBJECT = '' \ No newline at end of file + +WAIT_EVERY = 5 +DELAY_SEC = 0 \ No newline at end of file From 02b76b57554d10b052932e9faa36ce93ee56e97f Mon Sep 17 00:00:00 2001 From: thisfro Date: Sun, 9 Oct 2022 19:14:16 +0200 Subject: [PATCH 3/3] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa578ca..3c6a212 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ Easily send mails via SMTP and python ## Setup 1. Copy `vars.py.example` to `vars.py` -2. Setup `vars.py` with your credentials -3. Adapt `message.txt` and import `contacts.csv` +2. Setup `vars.py` with your credentials and config +3. Adapt `message.htmt` and save your contact list to `contacts.csv` ## Usage ```python mail.py```