Browse Source

Adding management of mail sending error in debug trace and frontend flash message while creating user

guillaume chanaud 7 years ago
parent
commit
099260d8f6

+ 10 - 2
tracim/tracim/controllers/admin/user.py View File

344
 
344
 
345
         api.save(user)
345
         api.save(user)
346
 
346
 
347
+        email_sent = True
347
         if send_email:
348
         if send_email:
348
             email_manager = get_email_manager()
349
             email_manager = get_email_manager()
349
-            email_manager.notify_created_account(user, password=password)
350
+            try:
351
+                email_manager.notify_created_account(user, password=password)
352
+            except Exception:
353
+                email_sent = False
350
 
354
 
351
         api.execute_created_user_actions(user)
355
         api.execute_created_user_actions(user)
352
-        tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
356
+        if not email_sent:
357
+            tg.flash(_('User {0} created but email was not sent to {1}').format(user.get_display_name(), user.email),
358
+                     CST.STATUS_WARNING)
359
+        else:
360
+            tg.flash(_('User {} created.').format(user.get_display_name()), CST.STATUS_OK)
353
         tg.redirect(self.url())
361
         tg.redirect(self.url())
354
 
362
 
355
     @classmethod
363
     @classmethod

BIN
tracim/tracim/i18n/en/LC_MESSAGES/tracim.mo View File


+ 6 - 2
tracim/tracim/lib/email.py View File

69
             logger.info(self, 'Connecting from SMTP server {}'.format(self._smtp_config.server))
69
             logger.info(self, 'Connecting from SMTP server {}'.format(self._smtp_config.server))
70
             self._smtp_connection = smtplib.SMTP(self._smtp_config.server, self._smtp_config.port)
70
             self._smtp_connection = smtplib.SMTP(self._smtp_config.server, self._smtp_config.port)
71
             self._smtp_connection.ehlo()
71
             self._smtp_connection.ehlo()
72
+
72
             if self._smtp_config.login:
73
             if self._smtp_config.login:
73
                 try:
74
                 try:
74
                     starttls_result = self._smtp_connection.starttls()
75
                     starttls_result = self._smtp_connection.starttls()
82
                     logger.debug(self, 'SMTP login result: {}'.format(login_res))
83
                     logger.debug(self, 'SMTP login result: {}'.format(login_res))
83
                 except Exception as e:
84
                 except Exception as e:
84
                     logger.debug(self, 'SMTP login error: {}'.format(e.__str__()))
85
                     logger.debug(self, 'SMTP login error: {}'.format(e.__str__()))
85
-                
86
+                    raise e
87
+
86
             logger.info(self, 'Connection OK')
88
             logger.info(self, 'Connection OK')
87
 
89
 
90
+
91
+
88
     def disconnect(self):
92
     def disconnect(self):
89
         if self._smtp_connection:
93
         if self._smtp_connection:
90
             logger.info(self, 'Disconnecting from SMTP server {}'.format(self._smtp_config.server))
94
             logger.info(self, 'Disconnecting from SMTP server {}'.format(self._smtp_config.server))
96
         if not self._is_active:
100
         if not self._is_active:
97
             logger.info(self, 'Not sending email to {} (service desactivated)'.format(message['To']))
101
             logger.info(self, 'Not sending email to {} (service desactivated)'.format(message['To']))
98
         else:
102
         else:
99
-            self.connect() # Acutally, this connects to SMTP only if required
103
+            self.connect() # Actually, this connects to SMTP only if required
100
             logger.info(self, 'Sending email to {}'.format(message['To']))
104
             logger.info(self, 'Sending email to {}'.format(message['To']))
101
             self._smtp_connection.send_message(message)
105
             self._smtp_connection.send_message(message)
102
 
106