summaryrefslogtreecommitdiff
path: root/src/mailman/mta/connection.py
diff options
context:
space:
mode:
authorBarry Warsaw2011-01-02 23:52:22 -0500
committerBarry Warsaw2011-01-02 23:52:22 -0500
commit5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d (patch)
tree6296162e7f68e2af68f7ed8ab9ccc7f1394ec084 /src/mailman/mta/connection.py
parent1b8c94f4ad4730b3251c9efd667db27245105b6c (diff)
downloadmailman-5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d.tar.gz
mailman-5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d.tar.zst
mailman-5d0d6a5afa34c61630a6442006e9ff2b87fb0c8d.zip
Diffstat (limited to 'src/mailman/mta/connection.py')
-rw-r--r--src/mailman/mta/connection.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/mailman/mta/connection.py b/src/mailman/mta/connection.py
index e832c2447..369e43570 100644
--- a/src/mailman/mta/connection.py
+++ b/src/mailman/mta/connection.py
@@ -38,7 +38,8 @@ log = logging.getLogger('mailman.smtp')
class Connection:
"""Manage a connection to the SMTP server."""
- def __init__(self, host, port, sessions_per_connection):
+ def __init__(self, host, port, sessions_per_connection,
+ smtp_user=None, smtp_pass=None):
"""Create a connection manager.
:param host: The host name of the SMTP server to connect to.
@@ -51,10 +52,17 @@ class Connection:
opened. Set to zero for an unlimited number of sessions per
connection (i.e. your MTA has no limit).
:type sessions_per_connection: integer
+ :param smtp_user: Optional SMTP authentication user name. If given,
+ `smtp_pass` must also be given.
+ :type smtp_user: str
+ :param smtp_pass: Optional SMTP authentication password. If given,
+ `smtp_user` must also be given.
"""
self._host = host
self._port = port
self._sessions_per_connection = sessions_per_connection
+ self._username = smtp_user
+ self._password = smtp_pass
self._session_count = None
self._connection = None
@@ -63,6 +71,9 @@ class Connection:
self._connection = smtplib.SMTP()
log.debug('Connecting to %s:%s', self._host, self._port)
self._connection.connect(self._host, self._port)
+ if self._username is not None and self._password is not None:
+ log.debug('Logging in')
+ self._connection.login(self._username, self._password)
self._session_count = self._sessions_per_connection
def sendmail(self, envsender, recipients, msgtext):