diff --git a/geruecht/configparser.py b/geruecht/configparser.py index e1ab855..dc519a0 100644 --- a/geruecht/configparser.py +++ b/geruecht/configparser.py @@ -10,7 +10,8 @@ default = { 'port': 0, 'user': '', 'passwd': '', - 'email': '' + 'email': '', + 'crypt': 'STARTTLS' } } @@ -61,6 +62,9 @@ class ConifgParser(): if 'email' not in self.config['Mail']: self.config['Mail']['email'] = default['Mail']['email'] LOGGER.info("No Config for email in Mail found. Set it to default") + if 'crypt' not in self.config['Mail']: + self.config['Mail']['crypt'] = default['Mail']['crypt'] + LOGGER.info("No Config for crypt in Mail found. Set it to default") self.mail = self.config['Mail'] LOGGER.info('Set Mailconfig: {}'.format(self.mail)) diff --git a/geruecht/controller/emailController.py b/geruecht/controller/emailController.py index b11eb40..ebad0da 100644 --- a/geruecht/controller/emailController.py +++ b/geruecht/controller/emailController.py @@ -3,24 +3,38 @@ from datetime import datetime from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.header import Header -from . import LOGGER +from geruecht import getLogger + +LOGGER = getLogger('E-MailController') class EmailController(): - def __init__(self, smtpServer, user, passwd, port = 587, email = ""): + def __init__(self, smtpServer, user, passwd, crypt, port=587, email=""): self.smtpServer = smtpServer self.port = port self.user = user self.passwd = passwd + self.crypt = crypt if email: self.email = email else: self.email = user + LOGGER.debug('Init EmailController with smtpServer={}, port={}, user={}, crypt={}, email={}'.format(smtpServer, user, port, crypt, self.email)) def __connect__(self): - self.smtp = smtplib.SMTP(self.smtpServer, self.port) - self.smtp.starttls() - self.smtp.login(self.user, self.passwd) + LOGGER.info('Connect to E-Mail-Server') + if self.crypt == 'SSL': + self.smtp = smtplib.SMTP_SSL(self.smtpServer, self.port) + log = self.smtp.ehlo() + LOGGER.debug(log) + if self.crypt == 'STARTTLS': + self.smtp = smtplib.SMTP(self.smtpServer, self.port) + log = self.smtp.ehlo() + LOGGER.debug(log) + log = self.smtp.starttls() + LOGGER.debug(log) + log = self.smtp.login(self.user, self.passwd) + LOGGER.debug(log) def sendMail(self, user): try: diff --git a/geruecht/controller/userController.py b/geruecht/controller/userController.py index b7210ae..ea562ca 100644 --- a/geruecht/controller/userController.py +++ b/geruecht/controller/userController.py @@ -10,7 +10,7 @@ from geruecht.exceptions import UsernameExistLDAP, UsernameExistDB, DatabaseExec db = dc.DatabaseController() ldap = lc.LDAPController(ldapConfig['dn']) -emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['port'], mailConfig['email']) +emailController = ec.EmailController(mailConfig['URL'], mailConfig['user'], mailConfig['passwd'], mailConfig['crypt'], mailConfig['port'], mailConfig['email']) class UserController(metaclass=Singleton):