##// END OF EJS Templates
mail: only bother admins when that really is the intention - not when there just not happens to be other recipients
Mads Kiilerich -
r4332:609e06b6 default
parent child Browse files
Show More
@@ -261,8 +261,8 b' def send_email(recipients, subject, body'
261 261 """
262 262 Sends an email with defined parameters from the .ini files.
263 263
264 :param recipients: list of recipients, it this is empty the defined email
265 address from field 'email_to' is used instead
264 :param recipients: list of recipients, if this is None, the defined email
265 address from field 'email_to' and all admins is used instead
266 266 :param subject: subject of the mail
267 267 :param body: body of the mail
268 268 :param html_body: html version of body
@@ -272,13 +272,18 b' def send_email(recipients, subject, body'
272 272 assert isinstance(recipients, list), recipients
273 273
274 274 email_config = config
275 subject = "%s %s" % (email_config.get('email_prefix', ''), subject)
276 if not recipients:
275 email_prefix = email_config.get('email_prefix', '')
276 if email_prefix:
277 subject = "%s %s" % (email_prefix, subject)
278 if recipients is None:
277 279 # if recipients are not defined we send to email_config + all admins
278 280 admins = [u.email for u in User.query()
279 281 .filter(User.admin == True).all()]
280 282 recipients = [email_config.get('email_to')] + admins
281 283 log.warning("recipients not specified for '%s' - sending to admins %s", subject, ' '.join(recipients))
284 elif not recipients:
285 log.error("No recipients specified")
286 return False
282 287
283 288 mail_from = email_config.get('app_email_from', 'Kallithea')
284 289 user = email_config.get('smtp_username')
@@ -82,8 +82,8 b' class NotificationModel(BaseModel):'
82 82
83 83 created_by_obj = self._get_user(created_by)
84 84
85 recipients_objs = []
85 86 if recipients:
86 recipients_objs = []
87 87 for u in recipients:
88 88 obj = self._get_user(u)
89 89 if obj:
@@ -95,12 +95,14 b' class NotificationModel(BaseModel):'
95 95 log.debug('sending notifications %s to %s' % (
96 96 type_, recipients_objs)
97 97 )
98 else:
98 elif recipients is None:
99 99 # empty recipients means to all admins
100 100 recipients_objs = User.query().filter(User.admin == True).all()
101 101 log.debug('sending notifications %s to admins: %s' % (
102 102 type_, recipients_objs)
103 103 )
104 #else: silently skip notification mails?
105
104 106 # TODO: inform user who are notified
105 107 notif = Notification.create(
106 108 created_by=created_by_obj, subject=subject,
General Comments 0
You need to be logged in to leave comments. Login now