Set default port values in MicromailClient constructor based on SSL and STARTTLS settings

This commit is contained in:
Edgar P. Burkhart 2025-05-19 12:34:55 +02:00
parent 36dc32fef3
commit 4c9ff09ea9
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -6,9 +6,8 @@ from datetime import datetime, timedelta, timezone
class MicromailClient:
def __init__(self, host, port, ssl=False, starttls=False):
def __init__(self, host, port=0, ssl=False, starttls=False):
self.host = host
self.port = port
if ssl and starttls:
raise Error("Cannot use both SSL and STARTTLS at the same time.")
@ -16,6 +15,15 @@ class MicromailClient:
self.ssl = ssl
self.starttls = starttls
if port == 0:
if ssl:
port = 465
elif starttls:
port = 587
else:
port = 25
self.port = port
self.socket = None
self.username = None