Browse Source

Add support for starttls and allow modification of SMTP server port

pull/2414/head
Adrien RAFFIN 12 years ago
committed by Ruud
parent
commit
7c5748ac87
  1. 11
      couchpotato/core/notifications/email/__init__.py
  2. 10
      couchpotato/core/notifications/email/main.py

11
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',
},

10
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 ""))

Loading…
Cancel
Save