From 5d950facabc68d0cb4af31a8f7e5c7dbea9d3bbf Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sat, 25 May 2024 11:52:26 +0200 Subject: [PATCH] Add a command to test the email config with --- hedgedoc-expire.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py index 98fc9ae..195933f 100644 --- a/hedgedoc-expire.py +++ b/hedgedoc-expire.py @@ -251,6 +251,18 @@ class HedgedocExpire: self.check_revisions_to_be_expired(db) self.check_notes_to_be_expired(db) + def cmd_emailcheck(self) -> None: + msg = MIMEMultipart() + msg['From'] = self.email_sender.mail_from + msg['To'] = self.email_sender.mail_from + msg['Subject'] = f'Hedgedoc Expire: Test Mail' + msg.attach(MIMEText(dedent(f'''\ + This is a test email to confirm proper configuration of the SMTP client. + + The admin team for {self.config.url} + '''))) + self.email_sender.send(msg) + def cmd_expire(self) -> None: with pgsql.Connection((self.config.postgres_hostname, self.config.postgres_port), self.config.postgres_username, self.config.postgres_password) as db: @@ -281,7 +293,7 @@ def main(): help='remove all notes not changed in these many days') parser.add_argument('-r', '--revisions', metavar='DAYS', type=float, default=14, help='remove all revisions created more than these many days ago') - parser.add_argument('command', choices=['check', 'cron', 'expire'], default='check', nargs='?', + parser.add_argument('command', choices=['check', 'cron', 'emailcheck', 'expire'], default='check', nargs='?', help='action to perform') parser.add_argument('-v', '--verbose', action='store_true', default=False, help='print more info while running') @@ -306,6 +318,8 @@ def main(): if seconds > 0: sleep(seconds) hedgedoc_expire.cmd_expire() + elif args.command == 'emailcheck': + hedgedoc_expire.cmd_emailcheck() elif args.command == 'expire': hedgedoc_expire.cmd_expire() else: