send confirmation mail, write to csv
This commit is contained in:
parent
0398c19aa5
commit
6c4c23703b
@ -247,7 +247,7 @@ def process_registrations(M):
|
|||||||
return participations
|
return participations
|
||||||
|
|
||||||
|
|
||||||
def send_confirmation(p=None):
|
def send_confirmation(p=None, csv_file=None):
|
||||||
if p is not None:
|
if p is not None:
|
||||||
assert(isinstance(p, Participation))
|
assert(isinstance(p, Participation))
|
||||||
content = "Dear %s," % (p.name if p else "participant")
|
content = "Dear %s," % (p.name if p else "participant")
|
||||||
@ -259,7 +259,7 @@ def send_confirmation(p=None):
|
|||||||
msg.set_content(content)
|
msg.set_content(content)
|
||||||
msg['Subject'] = 'Etho 2020 registration confirmation'
|
msg['Subject'] = 'Etho 2020 registration confirmation'
|
||||||
msg['From'] = EMAIL_ADDRESS
|
msg['From'] = EMAIL_ADDRESS
|
||||||
msg['To'] = 'jan.grewe@uni-tuebingen.de'
|
msg['To'] = p._email
|
||||||
msg['Reply-to'] = EMAIL_REPLY
|
msg['Reply-to'] = EMAIL_REPLY
|
||||||
|
|
||||||
s = smtplib.SMTP(SMTP_SERVER)
|
s = smtplib.SMTP(SMTP_SERVER)
|
||||||
@ -267,7 +267,17 @@ def send_confirmation(p=None):
|
|||||||
s.login(EMAIL_ACCOUNT, EMAIL_PSWD)
|
s.login(EMAIL_ACCOUNT, EMAIL_PSWD)
|
||||||
s.send_message(msg)
|
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()
|
s.quit()
|
||||||
|
|
||||||
|
|
||||||
@ -289,8 +299,8 @@ if __name__ == "__main__":
|
|||||||
new_participations = process_registrations(M)
|
new_participations = process_registrations(M)
|
||||||
for p in new_participations:
|
for p in new_participations:
|
||||||
print(p.name)
|
print(p.name)
|
||||||
p.save_to_csv()
|
csv_file = p.save_to_csv()
|
||||||
send_confirmation(p)
|
send_confirmation(p, csv_file)
|
||||||
M.close()
|
M.close()
|
||||||
M.logout()
|
M.logout()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user