From 7c5748ac87c3f6860f6f9e0dd27f172644c2c217 Mon Sep 17 00:00:00 2001 From: Adrien RAFFIN Date: Wed, 23 Oct 2013 10:35:32 +0200 Subject: [PATCH] Add support for starttls and allow modification of SMTP server port --- couchpotato/core/notifications/email/__init__.py | 11 +++++++++++ couchpotato/core/notifications/email/main.py | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/couchpotato/core/notifications/email/__init__.py b/couchpotato/core/notifications/email/__init__.py index b41cc8e..33c2f63 100644 --- a/couchpotato/core/notifications/email/__init__.py +++ b/couchpotato/core/notifications/email/__init__.py @@ -28,6 +28,11 @@ config = [{ 'name': 'smtp_server', 'label': 'SMTP server', }, + { 'name': 'smtp_port', + 'label': 'SMTP server port', + 'default': '25', + 'type': 'int', + }, { 'name': 'ssl', 'label': 'Enable SSL', @@ -35,6 +40,12 @@ config = [{ 'type': 'bool', }, { + 'name': 'starttls', + 'label': 'Enable StartTLS', + 'default': 0, + 'type': 'bool', + }, + { 'name': 'smtp_user', 'label': 'SMTP user', }, diff --git a/couchpotato/core/notifications/email/main.py b/couchpotato/core/notifications/email/main.py index 508e082..4d0b28b 100644 --- a/couchpotato/core/notifications/email/main.py +++ b/couchpotato/core/notifications/email/main.py @@ -22,6 +22,8 @@ class Email(Notification): smtp_server = self.conf('smtp_server') smtp_user = self.conf('smtp_user') smtp_pass = self.conf('smtp_pass') + smtp_port = self.conf('smtp_port') + starttls = self.conf('starttls') # Make the basic message message = MIMEText(toUnicode(message), _charset = Env.get('encoding')) @@ -31,9 +33,17 @@ class Email(Notification): try: # Open the SMTP connection, via SSL if requested + log.debug("Connecting to host %s on port %s" % (smtp_host, smtp_port)) log.debug("SMTP over SSL %s", ("enabled" if ssl == 1 else "disabled")) mailserver = smtplib.SMTP_SSL(smtp_server) if ssl == 1 else smtplib.SMTP(smtp_server) + if (starttls): + log.debug("Using StartTLS to initiate the connection with the SMTP server") + mailserver.starttls() + + # Say hello to the server + mailserver.ehlo() + # Check too see if an login attempt should be attempted if len(smtp_user) > 0: log.debug("Logging on to SMTP server using username \'%s\'%s", (smtp_user, " and a password" if len(smtp_pass) > 0 else ""))