Skip to content

Commit

Permalink
refactor test email variables
Browse files Browse the repository at this point in the history
  • Loading branch information
michael7nightingale committed Aug 9, 2023
1 parent ec6413a commit 66a2989
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BaseAppSettings(BaseSettings):
SECRET_KEY: str
EXPIRE_MINUTES: int

EMAIL_PORT: str
EMAIL_PORT: int
EMAIL_HOST: str
EMAIL_USER: str
EMAIL_PASSWORD: str
Expand Down
7 changes: 6 additions & 1 deletion src/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ def _configurate_db(self) -> None:

def _configure_services(self):
"""SMTP server configuration for sending email messages."""
self._smpt_server = create_server()
self._smpt_server = create_server(
host=self.settings.EMAIL_HOST,
port=self.settings.EMAIL_PORT,
password=self.settings.EMAIL_PASSWORD,
user=self.settings.EMAIL_USER
)
self.app.state.email_service = EmailService(smtp_server=self._smpt_server)

async def _load_data(self):
Expand Down
13 changes: 6 additions & 7 deletions src/services/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ def send_message(self, subject: str, to_addrs: list, body: str) -> None:
)


def create_server() -> SMTPServer:
settings = get_app_settings()
def create_server(host: str, port: int, user: str, password: str) -> SMTPServer:
server_ = SMTPServer(
port=settings.EMAIL_PORT,
host=settings.EMAIL_HOST,
from_addr=settings.EMAIL_USER,
port=port,
host=host,
from_addr=user,
)
server_.ehlo()
server_.login(
user=settings.EMAIL_USER,
password=settings.EMAIL_PASSWORD
user=user,
password=password
)
return server_

Expand Down

0 comments on commit 66a2989

Please sign in to comment.