示例#1
0
 def POST(self):
     form = web.input()
     subject = form['subject']
     email_body = form['body']
     to = form['to']
     receivers = []
     if to=="admins":
         receivers =[u for u in User.selectBy(admin=True, disabled=False)]
     elif to=="supadmins":
         receivers=[u for u in User.selectBy(super_admin=True).distinct()]
     elif to == 'contrib':
         id_channel=form['select_channel']
         c = PluginChannel.get(id_channel)
         receivers = [u for u in c.get_contribs()]
     elif to=="channel_editor_users":
         pc = PluginChannel.select()
         for elem in pc:
             if elem.plugin.name=="editor":
                 l1=[u1 for u1 in elem.get_admins()]
                 l2=[u2 for u2 in elem.get_contribs()]
                 list_users = l1+l2
                 receivers=[u for u in list_users]
     else:
       for s in Screen.select():
           receivers=[u for u in s.owners]
     try:
         for u in receivers:
             web.sendmail(web.config.smtp_sendername, u.email, subject, email_body,
                          headers={'Content-Type': 'text/html;charset=utf-8'})
     except smtplib.SMTPException:
         logger.error('An error occured when sending email ', exc_info=True)
     return web.seeother("/")
示例#2
0
 def post(self):
     form = self.form
     subject = form['subject']
     email_body = form['body']
     to = form['to']
     receivers = []
     if to == "admins":
         receivers = [u for u in User.selectBy(admin=True, disabled=False)]
     elif to == "supadmins":
         receivers = [u for u in User.selectBy(super_admin=True).distinct()]
     elif to == 'contrib':
         id_channel = form['select_channel']
         c = PluginChannel.get(id_channel)
         receivers = [u for u in c.get_contribs()]
     elif to == "channel_editor_users":
         pc = PluginChannel.select()
         for elem in pc:
             if elem.plugin.name == "editor":
                 l1 = [u1 for u1 in elem.get_admins()]
                 l2 = [u2 for u2 in elem.get_contribs()]
                 list_users = l1 + l2
                 receivers = [u for u in list_users]
     else:
         for s in Screen.select():
             receivers = [u for u in s.owners]
     try:
         mail = Mail(self.app)
         msg = Message(
             recipients=[u.email for u in receivers],
             subject=subject,
             body=email_body,
             extra_headers={'Content-Type': 'text/html;charset=utf-8'})
         mail.send(msg)
     except smtplib.SMTPException:
         logger.error('An error occured when sending email ', exc_info=True)
     resp.seeother("/")