From 172e935c3e874845e3015ad40f7b501a928abb57 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 7 Jul 2025 16:01:15 +0300 Subject: [PATCH] Add limit of connections to SMTP --- mastodon_email_bridge/mastodon_email_bridge.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mastodon_email_bridge/mastodon_email_bridge.py b/mastodon_email_bridge/mastodon_email_bridge.py index a0bc195..6567dca 100755 --- a/mastodon_email_bridge/mastodon_email_bridge.py +++ b/mastodon_email_bridge/mastodon_email_bridge.py @@ -51,6 +51,7 @@ class MastodonEmailBridge: ) self._init_log() self.last_translation_response = None + self.last_smtp_connection = None self._get_sent_posts() if 'templates_folder' in self.config: templates_folder=self.config['templates_folder'] @@ -188,6 +189,8 @@ class MastodonEmailBridge: def send_mail(self, data): '''Send an email with the post composed''' + if time.time() - self.last_smtp_connection < 1: + time.sleep(1) sender = self._str_template(self.config['sender'], data) recipient = self._str_template(self.config['recipient'], data) msg = MIMEMultipart('alternative') @@ -235,6 +238,7 @@ class MastodonEmailBridge: self._log.debug("Sending email for post with id '%s'...", data['id']) conn.sendmail(sender, recipient, msg.as_string()) conn.quit() + self.last_smtp_connection = time.time() self._log.debug("Adding entry to database...") cur = self.sqlite.cursor() res = cur.execute("SELECT id FROM sent_items WHERE id = ?", [(data['id'])]) @@ -470,6 +474,12 @@ class MastodonEmailBridge: default='en', help='Language destination for the translations' ) +@click.option( + '--connections-per-second', + '-c', + default=1, + help='Maximun number of SMTP connections per second' +) @click.option('--log-file', '-l', help="File to store all debug messages.") # @click.option("--dummy","-n", is_flag=True,