plugin misc account: fix send_email calls + admin email flag:

The `send_email` calls in `send_emails` passed the plugin `EmailSettings` as the `config`
argument, raising `AttributeError` on account creation and leading to the profile
deletion.

They now pass the main config via a new `email_settings`.

`credentials_xmpp_connect` takes a new `send_email` flag to let frontends skip the admin
notification email (notably useful in web local mode).
This commit is contained in:
Goffi 2026-11-03 23:06:54 +01:00
commit e8b3948ad0
2 changed files with 24 additions and 13 deletions

View file

@ -145,7 +145,7 @@ class MiscAccount(object):
host.bridge.add_method( host.bridge.add_method(
"credentials_xmpp_connect", "credentials_xmpp_connect",
".plugin", ".plugin",
in_sign="ss", in_sign="ssb",
out_sign="b", out_sign="b",
method=self.credentials_xmpp_connect, method=self.credentials_xmpp_connect,
async_=True, async_=True,
@ -293,11 +293,11 @@ class MiscAccount(object):
# there is no email when an existing XMPP account is used # there is no email when an existing XMPP account is used
body = f"New account created on {domain}: {profile} [{email or '<no email>'}]" body = f"New account created on {domain}: {profile} [{email or '<no email>'}]"
d_admin = sat_email.send_email( d_admin = sat_email.send_email(
self.get_email_conf(),
self.host.memory.config, self.host.memory.config,
admins_emails, admins_emails,
subject, subject,
body, body,
email_settings=self.get_email_conf(),
) )
admins_emails_txt = ", ".join(["<" + addr + ">" for addr in admins_emails]) 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 # XXX: this will not fail when the email address doesn't exist
# FIXME: check email reception to validate email given by the user # FIXME: check email reception to validate email given by the user
# FIXME: delete the profile if the email could not been sent? # 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( d_user.addCallbacks(
lambda __: log.debug( lambda __: log.debug(
"Account creation confirmation sent to <{}>".format(email) "Account creation confirmation sent to <{}>".format(email)
@ -689,12 +695,13 @@ class MiscAccount(object):
d.addCallbacks(deleted, errback) d.addCallbacks(deleted, errback)
return d 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. """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. Re-use given JID and XMPP password for the profile name and profile password.
@param jid_s (unicode): JID @param jid_s (unicode): JID
@param password (unicode): XMPP password @param password (unicode): XMPP password
@param send_email (bool): send the administrator notification email
@return Deferred(bool) @return Deferred(bool)
@raise exceptions.PasswordError, exceptions.ConflictError @raise exceptions.PasswordError, exceptions.ConflictError
""" """
@ -716,7 +723,8 @@ class MiscAccount(object):
) )
def connected(result): def connected(result):
self.send_emails(None, profile=jid_s) if send_email:
self.send_emails(None, profile=jid_s)
return result return result
def remove_profile( def remove_profile(

View file

@ -34,6 +34,7 @@ def send_email(
subject: str = "", subject: str = "",
body: str = "", body: str = "",
from_email: str | None = None, from_email: str | None = None,
email_settings: tools_config.EmailSettings | None = None,
) -> defer.Deferred: ) -> defer.Deferred:
"""Send an email using Libervia configuration """Send an email using Libervia configuration
@ -43,12 +44,14 @@ def send_email(
@param subject: subject of the message @param subject: subject of the message
@param body: body of the message @param body: body of the message
@param from_email: address of the sender @param from_email: address of the sender
@param email_settings: ``EmailSettings`` to use, default to ``config.email``
@return:Same as smtp.sendmail. @return:Same as smtp.sendmail.
""" """
if isinstance(to_emails, str): if isinstance(to_emails, str):
to_emails = to_emails.split() to_emails = to_emails.split()
email_host = config.email.server settings = email_settings or config.email
email_from = from_email or config.email.from_ email_host = settings.server
email_from = from_email or settings.from_
# we suppose that email domain and XMPP domain are identical # we suppose that email domain and XMPP domain are identical
domain = config.common.xmpp_domain domain = config.common.xmpp_domain
@ -60,12 +63,12 @@ def send_email(
if email_from is None: if email_from is None:
email_from = "no_reply@" + domain email_from = "no_reply@" + domain
email_sender_domain = config.email.sender_domain or domain email_sender_domain = settings.sender_domain or domain
email_port = config.email.port email_port = settings.port
email_username = config.email.username email_username = settings.username
email_password = config.email.password email_password = settings.password
email_auth = config.email.auth email_auth = settings.auth
email_starttls = config.email.starttls email_starttls = settings.starttls
msg = MIMEText(body, "plain", "UTF-8") msg = MIMEText(body, "plain", "UTF-8")
msg["Subject"] = subject msg["Subject"] = subject