Skip to content
Snippets Groups Projects
Commit 32a9ed19 authored by Julian Rother's avatar Julian Rother
Browse files

Fixed some issues in mail.py

parent ff053365
No related branches found
No related tags found
No related merge requests found
......@@ -14,23 +14,22 @@ def send_message(msgtype, recipients, **kwargs):
try:
msg['Subject'] = render_template('mails/'+msgtype+'.subject', **kwargs)
msg.set_content(render_template('mails/'+msgtype+'.body', **kwargs))
except:
traceback.print_exc()
return
if 'MAIL_SERVER' not in config:
return
s = smtplib.SMTP(config['MAIL_SERVER'])
s.send_message(msg)
s.quit()
except:
traceback.print_exc()
def notify_users(msgtype, uids, **kwargs):
recipients = []
exclude = kwargs.pop('exclude_uids', [])
for uid in uids:
user = query('SELECT * FROM users WHERE id = ?', uid)
if user[0]['id'] in exclude:
if not user or user[0]['id'] in exclude:
continue
if not user or not user[0]['fsacc'] or not user[0]['mail_notifications']:
if not user[0]['fsacc'] or not user[0]['mail_notifications']:
continue
if msgtype in user[0] and not user[0][msgtype]:
continue
......@@ -39,14 +38,17 @@ def notify_users(msgtype, uids, **kwargs):
config['MAIL_SUFFIX']))
else:
recipients.append('%s@%s'%(user[0]['fsacc'], config['MAIL_SUFFIX']))
if recipients:
if kwargs.pop('importend', False):
kwargs['cc'] = [config['MAIL_DEFAULT']]
else:
cc = kwargs.get('cc', [])
if kwargs.pop('importend', False):
recipients = [config['MAIL_DEFAULT']]
else:
cc.append(config['MAIL_DEFAULT'])
if kwargs.pop('notify_admins', False):
cc.append(config['MAIL_ADMINS'])
if not recipients:
recipients = cc
cc = []
if not recipients:
return
kwargs['cc'] = cc
send_message(msgtype, recipients, **kwargs)
def notify_mods(msgtype, course_id, **kwargs):
......@@ -63,5 +65,4 @@ def notify_admins(msgtype, **kwargs):
send_message(msgtype, [config['MAIL_ADMINS']], **kwargs)
except:
traceback.print_exc()
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment