Compare commits

...

2 commits

Author SHA1 Message Date
7d7bc5b28e fix permissions 2025-07-07 16:01:42 +03:00
172e935c3e Add limit of connections to SMTP 2025-07-07 16:01:15 +03:00
4 changed files with 10 additions and 0 deletions

0
mastodon_email_bridge/__init__.py Normal file → Executable file
View file

View file

@ -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,

0
setup.py Normal file → Executable file
View file

0
wrapper.sh Normal file → Executable file
View file