finished ##177

This commit is contained in:
Tim Gröger 2020-02-26 22:13:44 +01:00
parent 89ad67de39
commit 80fbe2b759
3 changed files with 25 additions and 7 deletions

View File

@ -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))

View File

@ -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):
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)
self.smtp.starttls()
self.smtp.login(self.user, self.passwd)
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:

View File

@ -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):