diff --git a/libervia/backend/plugins/plugin_misc_account.py b/libervia/backend/plugins/plugin_misc_account.py index d6d904dd..6d944ad2 100644 --- a/libervia/backend/plugins/plugin_misc_account.py +++ b/libervia/backend/plugins/plugin_misc_account.py @@ -145,7 +145,7 @@ class MiscAccount(object): host.bridge.add_method( "credentials_xmpp_connect", ".plugin", - in_sign="ss", + in_sign="ssb", out_sign="b", method=self.credentials_xmpp_connect, async_=True, @@ -293,11 +293,11 @@ class MiscAccount(object): # there is no email when an existing XMPP account is used body = f"New account created on {domain}: {profile} [{email or ''}]" d_admin = sat_email.send_email( - self.get_email_conf(), self.host.memory.config, admins_emails, subject, body, + email_settings=self.get_email_conf(), ) admins_emails_txt = ", ".join(["<" + addr + ">" for addr in admins_emails]) @@ -326,7 +326,13 @@ class MiscAccount(object): # 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 = sat_email.send_email(self.get_email_conf, [email], subject, body) + d_user = sat_email.send_email( + self.host.memory.config, + [email], + subject, + body, + email_settings=self.get_email_conf(), + ) d_user.addCallbacks( lambda __: log.debug( "Account creation confirmation sent to <{}>".format(email) @@ -689,12 +695,13 @@ class MiscAccount(object): d.addCallbacks(deleted, errback) return d - def credentials_xmpp_connect(self, jid_s, password): + def credentials_xmpp_connect(self, jid_s, password, send_email=True): """Create and connect a new SàT profile using the given XMPP credentials. Re-use given JID and XMPP password for the profile name and profile password. @param jid_s (unicode): JID @param password (unicode): XMPP password + @param send_email (bool): send the administrator notification email @return Deferred(bool) @raise exceptions.PasswordError, exceptions.ConflictError """ @@ -716,7 +723,8 @@ class MiscAccount(object): ) def connected(result): - self.send_emails(None, profile=jid_s) + if send_email: + self.send_emails(None, profile=jid_s) return result def remove_profile( diff --git a/libervia/backend/tools/common/email.py b/libervia/backend/tools/common/email.py index 2a7be733..cfad14f0 100644 --- a/libervia/backend/tools/common/email.py +++ b/libervia/backend/tools/common/email.py @@ -34,6 +34,7 @@ def send_email( subject: str = "", body: str = "", from_email: str | None = None, + email_settings: tools_config.EmailSettings | None = None, ) -> defer.Deferred: """Send an email using Libervia configuration @@ -43,12 +44,14 @@ def send_email( @param subject: subject of the message @param body: body of the message @param from_email: address of the sender + @param email_settings: ``EmailSettings`` to use, default to ``config.email`` @return:Same as smtp.sendmail. """ if isinstance(to_emails, str): to_emails = to_emails.split() - email_host = config.email.server - email_from = from_email or config.email.from_ + settings = email_settings or config.email + email_host = settings.server + email_from = from_email or settings.from_ # we suppose that email domain and XMPP domain are identical domain = config.common.xmpp_domain @@ -60,12 +63,12 @@ def send_email( if email_from is None: email_from = "no_reply@" + domain - email_sender_domain = config.email.sender_domain or domain - email_port = config.email.port - email_username = config.email.username - email_password = config.email.password - email_auth = config.email.auth - email_starttls = config.email.starttls + email_sender_domain = settings.sender_domain or domain + email_port = settings.port + email_username = settings.username + email_password = settings.password + email_auth = settings.auth + email_starttls = settings.starttls msg = MIMEText(body, "plain", "UTF-8") msg["Subject"] = subject