diff options
| author | J08nY | 2017-03-13 02:14:26 +0100 |
|---|---|---|
| committer | J08nY | 2017-07-24 18:44:19 +0200 |
| commit | ad463598885ecc91bee9fbca5aea9fcb4e9f627e (patch) | |
| tree | 9363afa79afaf75c32742c57b6e1cee8754d7a32 /src/mailman/mta/base.py | |
| parent | 02826321d0430d7ffc1f674eeff4221941689ef7 (diff) | |
| download | mailman-mta-smtps-starttls.tar.gz mailman-mta-smtps-starttls.tar.zst mailman-mta-smtps-starttls.zip | |
Add SMTPS/STARTTLS support.mta-smtps-starttls
- Adds SMTP over SSL/TLS and STARTTLS support to the outgoing
delivery by spliting the Connection class into three separate
classes with logic for SMTP, SMTP over SSL/TLS and STARTTLS.
- The Delivery class loads the added configuratio values and
selects the appropriate connection based on the configured
protocol.
- This requires aiosmtpd at least 1.1a1 for tests to pass,
as SMTPS support was added there in:
https://github.com/aio-libs/aiosmtpd/commit/0d33554c4787e575b7dd31b574259c0876dcc9f8
Diffstat (limited to '')
| -rw-r--r-- | src/mailman/mta/base.py | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/mailman/mta/base.py b/src/mailman/mta/base.py index 4cc7742e8..b182da027 100644 --- a/src/mailman/mta/base.py +++ b/src/mailman/mta/base.py @@ -22,9 +22,12 @@ import socket import logging import smtplib +from lazr.config import as_boolean from mailman.config import config +from mailman.interfaces.configuration import InvalidConfigurationError from mailman.interfaces.mta import IMailTransportAgentDelivery -from mailman.mta.connection import Connection +from mailman.mta.connection import ( + SMTPConnection, SMTPSConnection, STARTTLSConnection) from public import public from zope.interface import implementer @@ -39,12 +42,30 @@ class BaseDelivery: def __init__(self): """Create a basic deliverer.""" + host = config.mta.smtp_host + port = int(config.mta.smtp_port) username = (config.mta.smtp_user if config.mta.smtp_user else None) password = (config.mta.smtp_pass if config.mta.smtp_pass else None) - self._connection = Connection( - config.mta.smtp_host, int(config.mta.smtp_port), - int(config.mta.max_sessions_per_connection), - username, password) + protocol = config.mta.smtp_protocol + verify_cert = as_boolean(config.mta.smtp_verify_cert) + verify_hostname = as_boolean(config.mta.smtp_verify_hostname) + max_session_count = int(config.mta.max_sessions_per_connection) + + proto = protocol.lower() + if proto == 'smtp': + self._connection = SMTPConnection(host, port, max_session_count, + username, password) + elif proto == 'smtps': + self._connection = SMTPSConnection(host, port, max_session_count, + verify_cert, verify_hostname, + username, password) + elif proto == 'starttls': + self._connection = STARTTLSConnection(host, port, + max_session_count, + verify_cert, verify_hostname, + username, password) + else: + raise InvalidConfigurationError('mta.smtp_protocol', protocol) def _deliver_to_recipients(self, mlist, msg, msgdata, recipients): """Low-level delivery to a set of recipients. |
