mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-07-29 15:55:47 -05:00
IPA-EPN: add smtp_delay to limit the velocity of e-mails sent
Provide a knob so the mail queue doesn't get completely flooded with new e-mails. Default to no wait, value in milliseconds. https://pagure.io/freeipa/issue/3687 Signed-off-by: Rob Crittenden <rcritten@redhat.com> Reviewed-By: Francois Cami <fcami@redhat.com>
This commit is contained in:
@@ -70,6 +70,9 @@ Specifies the type of secure connection to make. Options are: none, starttls and
|
|||||||
Specifies the From e-mail address value in the e-mails sent. The default is
|
Specifies the From e-mail address value in the e-mails sent. The default is
|
||||||
root@localhost. Bounces will be sent here.
|
root@localhost. Bounces will be sent here.
|
||||||
.TP
|
.TP
|
||||||
|
.B smtp_delay <milliseconds>
|
||||||
|
Time to wait, in milliseconds, between each e-mail sent to try to avoid overloading the mail queue.
|
||||||
|
.TP
|
||||||
.B mail_from <address>
|
.B mail_from <address>
|
||||||
Specifies the From: e-mal address value in the e-mails sent. The default is
|
Specifies the From: e-mal address value in the e-mails sent. The default is
|
||||||
noreply@ipadefaultemaildomain. This value can be found by running
|
noreply@ipadefaultemaildomain. This value can be found by running
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import os
|
|||||||
import pwd
|
import pwd
|
||||||
import logging
|
import logging
|
||||||
import smtplib
|
import smtplib
|
||||||
|
import time
|
||||||
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
@@ -57,6 +58,7 @@ EPN_CONFIG = {
|
|||||||
"smtp_timeout": 60,
|
"smtp_timeout": 60,
|
||||||
"smtp_security": "none",
|
"smtp_security": "none",
|
||||||
"smtp_admin": "root@localhost",
|
"smtp_admin": "root@localhost",
|
||||||
|
"smtp_delay": None,
|
||||||
"mail_from": None,
|
"mail_from": None,
|
||||||
"notify_ttls": "28,14,7,3,1",
|
"notify_ttls": "28,14,7,3,1",
|
||||||
"msg_charset": "utf8",
|
"msg_charset": "utf8",
|
||||||
@@ -366,6 +368,13 @@ class EPN(admintool.AdminTool):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise RuntimeError('Failed to parse notify_ttls: \'%s\': %s' %
|
raise RuntimeError('Failed to parse notify_ttls: \'%s\': %s' %
|
||||||
(api.env.notify_ttls, e))
|
(api.env.notify_ttls, e))
|
||||||
|
if api.env.smtp_delay:
|
||||||
|
try:
|
||||||
|
float(api.env.smtp_delay)
|
||||||
|
except ValueError as e:
|
||||||
|
raise RuntimeError('smtp_delay is misformatted: %s' % e)
|
||||||
|
if float(api.env.smtp_delay) < 0:
|
||||||
|
raise RuntimeError('smtp_delay cannot be less than zero')
|
||||||
|
|
||||||
def _parse_configuration(self):
|
def _parse_configuration(self):
|
||||||
"""
|
"""
|
||||||
@@ -511,6 +520,8 @@ class EPN(admintool.AdminTool):
|
|||||||
"Notified %s (%s). Password expiring in %d days at %s.",
|
"Notified %s (%s). Password expiring in %d days at %s.",
|
||||||
entry["mail"], entry["uid"], (expdate - now).days,
|
entry["mail"], entry["uid"], (expdate - now).days,
|
||||||
expdate)
|
expdate)
|
||||||
|
if api.env.smtp_delay:
|
||||||
|
time.sleep(float(api.env.smtp_delay) / 1000)
|
||||||
self._mailer.cleanup()
|
self._mailer.cleanup()
|
||||||
|
|
||||||
def _gentestdata(self):
|
def _gentestdata(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user