plugin misc_account: fixes sending email (twisted.mail.smtp.sendmail doesn't want unicode)
This commit is contained in:
parent
e45ceec338
commit
f445c844c2
1 changed files with 15 additions and 15 deletions
|
|
@ -279,7 +279,19 @@ class MiscAccount(object):
|
|||
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 @@ class MiscAccount(object):
|
|||
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 @@ http://www.salut-a-toi.org
|
|||
# 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])
|
||||
|
|
|
|||
Loading…
Reference in a new issue