Parameterize everything

This commit is contained in:
Jannis Portmann 2022-10-09 19:14:07 +02:00
parent f6abda8772
commit 0bb4a1d06c
2 changed files with 14 additions and 4 deletions

11
mail.py
View file

@ -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()

View file

@ -1,5 +1,10 @@
SUBJECT = ''
EMAIL_COLUMN = ''
MY_ADDRESS = 'example@domain.tld'
PASSWORD = 'p4ssw0rd'
HOST = 'mail.domain.tld'
PORT = 587
SUBJECT = ''
WAIT_EVERY = 5
DELAY_SEC = 0