From edfd3c0719385b78784caa32905c78d19a6a13f9 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Fri, 19 Jun 2020 23:41:16 +0200 Subject: [PATCH] add disable_mailbox to shell --- shell.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/shell.py b/shell.py index 1c31bbb9..8e5e8b43 100644 --- a/shell.py +++ b/shell.py @@ -114,6 +114,37 @@ def migrate_domain_trash(): db.session.commit() +def disable_mailbox(mailbox_id): + """disable a mailbox and all of its aliases""" + mailbox = Mailbox.get(mailbox_id) + mailbox.verified = False + for alias in mailbox.aliases: + alias.enabled = False + + db.session.commit() + + email_msg = f"""Hi, + + Your mailbox {mailbox.email} cannot receive emails. + To avoid forwarding emails to an invalid mailbox, we have disabled this mailbox along with all of its aliases. + + If this is a mistake, please reply to this email. + + Thanks, + SimpleLogin team. + """ + + try: + send_email( + mailbox.user.email, + f"{mailbox.email} is disabled", + email_msg, + email_msg.replace("\n", "
"), + ) + except Exception: + LOG.error("Cannot send disable mailbox email to %s", mailbox.user) + + app = create_app() with app.app_context():