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): ...@@ -14,23 +14,22 @@ def send_message(msgtype, recipients, **kwargs):
try: try:
msg['Subject'] = render_template('mails/'+msgtype+'.subject', **kwargs) msg['Subject'] = render_template('mails/'+msgtype+'.subject', **kwargs)
msg.set_content(render_template('mails/'+msgtype+'.body', **kwargs)) msg.set_content(render_template('mails/'+msgtype+'.body', **kwargs))
except:
traceback.print_exc()
return
if 'MAIL_SERVER' not in config: if 'MAIL_SERVER' not in config:
return return
s = smtplib.SMTP(config['MAIL_SERVER']) s = smtplib.SMTP(config['MAIL_SERVER'])
s.send_message(msg) s.send_message(msg)
s.quit() s.quit()
except:
traceback.print_exc()
def notify_users(msgtype, uids, **kwargs): def notify_users(msgtype, uids, **kwargs):
recipients = [] recipients = []
exclude = kwargs.pop('exclude_uids', []) exclude = kwargs.pop('exclude_uids', [])
for uid in uids: for uid in uids:
user = query('SELECT * FROM users WHERE id = ?', uid) user = query('SELECT * FROM users WHERE id = ?', uid)
if user[0]['id'] in exclude: if not user or user[0]['id'] in exclude:
continue 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 continue
if msgtype in user[0] and not user[0][msgtype]: if msgtype in user[0] and not user[0][msgtype]:
continue continue
...@@ -39,14 +38,17 @@ def notify_users(msgtype, uids, **kwargs): ...@@ -39,14 +38,17 @@ def notify_users(msgtype, uids, **kwargs):
config['MAIL_SUFFIX'])) config['MAIL_SUFFIX']))
else: else:
recipients.append('%s@%s'%(user[0]['fsacc'], config['MAIL_SUFFIX'])) recipients.append('%s@%s'%(user[0]['fsacc'], config['MAIL_SUFFIX']))
if recipients: cc = kwargs.get('cc', [])
if kwargs.pop('importend', False):
kwargs['cc'] = [config['MAIL_DEFAULT']]
else:
if kwargs.pop('importend', False): if kwargs.pop('importend', False):
recipients = [config['MAIL_DEFAULT']] cc.append(config['MAIL_DEFAULT'])
else: if kwargs.pop('notify_admins', False):
cc.append(config['MAIL_ADMINS'])
if not recipients:
recipients = cc
cc = []
if not recipients:
return return
kwargs['cc'] = cc
send_message(msgtype, recipients, **kwargs) send_message(msgtype, recipients, **kwargs)
def notify_mods(msgtype, course_id, **kwargs): def notify_mods(msgtype, course_id, **kwargs):
...@@ -63,5 +65,4 @@ def notify_admins(msgtype, **kwargs): ...@@ -63,5 +65,4 @@ def notify_admins(msgtype, **kwargs):
send_message(msgtype, [config['MAIL_ADMINS']], **kwargs) send_message(msgtype, [config['MAIL_ADMINS']], **kwargs)
except: except:
traceback.print_exc() 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