Add limit of connections to SMTP
This commit is contained in:
parent
76e25393d0
commit
172e935c3e
1 changed files with 10 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue