Example #1
0
 def _get_message_data(self, env_id, event_name, notif_type, lang, curs):
     """
     returns (message_data_dict, NotificationProcessing)
     """
     n_p = NotificationProcessing()
     try:
         self._check_emailing_enabled(n_p)
         notif = self._get_notification(n_p, env_id, event_name, curs)
         n_p.message_data = self._extract_message(n_p, notif, lang)
         n_p.is_processable = True
     except HelixauthError:
         pass
     except Exception, e:
         n_p.add_step(n_p.STEP_UNEXPECTED_ERROR)
         logger.exception("Notification processing error: %s", e)
Example #2
0
 def _send_email(self, to, n_p, tpl_data):
     if n_p.is_processable:
         try:
             msg_d = n_p.message_data
             msg_text = msg_d[m.EMAIL_MSG_FIELD_NAME] % tpl_data
             msg = MIMEText(msg_text, _charset='utf8')
             msg['Subject'] = msg_d[m.EMAIL_SUBJ_FIELD_NAME]
             msg['From'] = settings.email_notifications_sender
             msg['To'] = to
             s = smtplib.SMTP(settings.email_server)
             s.sendmail(settings.email_notifications_sender, [to],
                 msg.as_string())
             s.quit()
             n_p.add_step(n_p.STEP_NOTIFICATION_SENT)
             n_p.is_sent = True
         except Exception, e:
             n_p.add_step(n_p.STEP_NOTIFICATION_SENDING_ERROR)
             logger.exception("Sending email failed: %s", e)