send confirmation mail, write to csv

This commit is contained in:
Jan Grewe 2019-08-21 17:36:42 +02:00
parent 0398c19aa5
commit 6c4c23703b

View File

@ -247,7 +247,7 @@ def process_registrations(M):
return participations
def send_confirmation(p=None):
def send_confirmation(p=None, csv_file=None):
if p is not None:
assert(isinstance(p, Participation))
content = "Dear %s," % (p.name if p else "participant")
@ -259,7 +259,7 @@ def send_confirmation(p=None):
msg.set_content(content)
msg['Subject'] = 'Etho 2020 registration confirmation'
msg['From'] = EMAIL_ADDRESS
msg['To'] = 'jan.grewe@uni-tuebingen.de'
msg['To'] = p._email
msg['Reply-to'] = EMAIL_REPLY
s = smtplib.SMTP(SMTP_SERVER)
@ -267,7 +267,17 @@ def send_confirmation(p=None):
s.login(EMAIL_ACCOUNT, EMAIL_PSWD)
s.send_message(msg)
if csv_file and p:
csv_msg = EmailMessage()
csv_msg['Subject'] = 'New Registration ' + p.name if p else ""
csv_msg['From'] = EMAIL_ADDRESS
csv_msg['To'] = p._email
with open(csv_file, 'rb') as fp:
file_data = fp.read()
csv_msg.add_attachment(file_data, maintype='text',
subtype="comma-separated-values")
s.send_message(csv_msg)
s.quit()
@ -289,8 +299,8 @@ if __name__ == "__main__":
new_participations = process_registrations(M)
for p in new_participations:
print(p.name)
p.save_to_csv()
send_confirmation(p)
csv_file = p.save_to_csv()
send_confirmation(p, csv_file)
M.close()
M.logout()