plugin misc_account: fixes login messages when sending emails

This commit is contained in:
souliane 2015-12-22 16:20:25 +01:00
commit 55307fb62a

View file

@ -230,28 +230,21 @@ class MiscAccount(object):
def sendEmails(self, email, jid_s, password, profile):
# time to send the email
_email_host = self.getConfig('email_server')
_email_from = self.getConfig("email_from")
email_host = self.getConfig('email_server')
email_from = self.getConfig("email_from")
domain = self.getConfig('new_account_domain')
def email_ok(ignore):
log.debug(u"Account creation email sent to %s" % email)
def email_ko(ignore):
# TODO: return error code to user
log.error(u"Failed to send email to %s" % email)
# email to the administrator
body = (u"""New account created: %(profile)s [%(email)s]""" % {'profile': profile, 'email': email}).encode('utf-8')
msg = MIMEText(body, 'plain', 'UTF-8')
msg['Subject'] = _('New Libervia account created')
msg['From'] = _email_from
msg['From'] = email_from
msg['To'] = self.getConfig('admin_email')
d_admin = sendmail(_email_host, _email_from, self.getConfig('admin_email'), msg.as_string())
d_admin.addCallbacks(email_ok, email_ko)
admin_email = self.getConfig('admin_email')
d_admin = sendmail(email_host, email_from, admin_email, msg.as_string())
d_admin.addCallbacks(lambda dummy: log.debug(u"Account creation notification sent to admin <%s>" % admin_email),
lambda dummy: log.error(u"Failed to send account creation notification to admin <%s>" % admin_email))
if not email:
return d_admin
@ -279,12 +272,16 @@ http://www.salut-a-toi.org
""") % {'profile': profile, 'jid_s': jid_s, 'domain': domain}).encode('utf-8')
msg = MIMEText(body, 'plain', 'UTF-8')
msg['Subject'] = _(u'Libervia account created')
msg['From'] = _email_from
msg['From'] = email_from
msg['To'] = email
d_user = sendmail(_email_host, _email_from, email, msg.as_string())
d_user.addCallbacks(email_ok, email_ko)
def email_ko(dummy):
# TODO: return error code to user
log.error(u"Failed to send account creation confirmation to <%s>" % email)
d_user = sendmail(email_host, email_from, email, msg.as_string())
d_user.addCallbacks(lambda dummy: log.debug(u"Account creation confirmation sent to <%s>" % email),
email_ko)
return defer.DeferredList([d_user, d_admin])
def getNewAccountDomain(self):