sh_cpl/src/cpl/mailing/email_client_settings.py

60 lines
1.7 KiB
Python
Raw Normal View History

2020-12-20 14:49:43 +01:00
import traceback
2021-03-03 10:47:52 +01:00
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
from cpl.console.console import Console
2021-03-12 16:06:30 +01:00
from cpl.mailing.email_client_settings_name_enum import EMailClientSettingsNameEnum
2020-12-20 14:49:43 +01:00
2021-03-03 10:47:52 +01:00
class EMailClientSettings(ConfigurationModelABC):
2020-12-20 14:49:43 +01:00
def __init__(self):
2021-03-03 10:47:52 +01:00
ConfigurationModelABC.__init__(self)
2020-12-20 14:49:43 +01:00
self._host: str = ''
self._port: int = 0
self._user_name: str = ''
self._credentials: str = ''
@property
def host(self) -> str:
return self._host
@host.setter
def host(self, host: str) -> None:
self._host = host
@property
def port(self) -> int:
return self._port
@port.setter
def port(self, port: int) -> None:
self._port = port
@property
def user_name(self) -> str:
return self._user_name
@user_name.setter
def user_name(self, user_name: str) -> None:
self._user_name = user_name
@property
def credentials(self) -> str:
return self._credentials
@credentials.setter
def credentials(self, credentials: str) -> None:
self._credentials = credentials
def from_dict(self, settings: dict):
try:
2021-03-12 16:06:30 +01:00
self._host = settings[EMailClientSettingsNameEnum.host.value]
self._port = settings[EMailClientSettingsNameEnum.port.value]
self._user_name = settings[EMailClientSettingsNameEnum.user_name.value]
self._credentials = settings[EMailClientSettingsNameEnum.credentials.value]
2020-12-20 14:49:43 +01:00
except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')