changeset 1898:31b8a58cfcf5

plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
author souliane <souliane@mailoo.org>
date Wed, 09 Mar 2016 11:52:18 +0100
parents e15c7d71ae76
children 7c97554a84d5
files src/plugins/plugin_misc_account.py
diffstat 1 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_account.py	Wed Mar 09 11:17:32 2016 +0100
+++ b/src/plugins/plugin_misc_account.py	Wed Mar 09 11:52:18 2016 +0100
@@ -279,7 +279,19 @@
         email_auth = C.bool(self.getConfig("email_auth"))
         domain = self.getConfig('new_account_domain')
 
-        # email to the administrator
+        def sendEmail(recipients, msg):
+            return sendmail(email_host.encode("utf-8"),
+                            email_from.encode("utf-8"),
+                            [email.encode("utf-8") for email in recipients],
+                            msg.as_string(),
+                            senderDomainName=email_sender_domain.encode("utf-8"),
+                            port=email_port,
+                            username=email_username.encode("utf-8"),
+                            password=email_password.encode("utf-8"),
+                            requireAuthentication=email_starttls,
+                            requireTransportSecurity=email_auth)
+
+        # email to the administrators
         admins_emails = self.getConfig('email_admins_list')
         if not admins_emails:
             log.warning(u"No known admin email, we can't send email to administrator(s).\nPlease fill email_admins_list parameter")
@@ -291,13 +303,7 @@
             msg['From'] = email_from
             msg['To'] = ", ".join(admins_emails)
 
-            d_admin = sendmail(email_host, email_from, admins_emails, msg.as_string(),
-                senderDomainName=email_sender_domain,
-                port=email_port,
-                username=email_username,
-                password=email_password,
-                requireAuthentication=email_starttls,
-                requireTransportSecurity=email_auth)
+            d_admin = sendEmail(admins_emails, msg)
         admins_emails_txt = u', '.join([u"<{}>".format(addr) for addr in admins_emails])
         d_admin.addCallbacks(lambda dummy: log.debug(u"Account creation notification sent to admin(s) {}".format(admins_emails_txt)),
                              lambda dummy: log.error(u"Failed to send account creation notification to admin {}".format(admins_emails_txt)))
@@ -335,13 +341,7 @@
         # XXX: this will not fail when the email address doesn't exist
         # FIXME: check email reception to validate email given by the user
         # FIXME: delete the profile if the email could not been sent?
-        d_user = sendmail(email_host, email_from, email, msg.as_string(),
-            senderDomainName=email_sender_domain,
-            port=email_port,
-            username=email_username,
-            password=email_password,
-            requireAuthentication=email_starttls,
-            requireTransportSecurity=email_auth)
+        d_user = sendEmail([email], msg)
         d_user.addCallbacks(lambda dummy: log.debug(u"Account creation confirmation sent to <%s>" % email),
                             email_ko)
         return defer.DeferredList([d_user, d_admin])