encode username/password in SMTP auth only for Python 2, fix #146

This commit is contained in:
Martin Zimmermann 2015-03-04 21:44:39 +01:00
parent 596acb7f79
commit f5566c1325

View File

@ -63,11 +63,16 @@ class SMTP(object):
timeout=self.conf.getint('timeout'))
if self.conf.get('security') == 'starttls':
self.client.starttls();
self.client.starttls()
if self.conf.get('username') and self.conf.get('password'):
self.client.login(self.conf.get('username').encode('ascii', errors='ignore'),
self.conf.get('password').encode('ascii', errors='ignore'))
username = self.conf.get('username')
password = self.conf.get('password')
if username is not None and password is not None:
if PY2K:
username = username.encode('ascii')
password = password.encode('ascii')
self.client.login(username, password)
return self.client