# HG changeset patch # User souliane # Date 1457520738 -3600 # Node ID 31b8a58cfcf534db0e8d298cf8d6d302e1951c94 # Parent e15c7d71ae76d594feb28939bd16bd29ca306215 plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode) diff -r e15c7d71ae76 -r 31b8a58cfcf5 src/plugins/plugin_misc_account.py --- 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])