Bank Services tested and completed
This commit is contained in:
@@ -10,19 +10,18 @@ class Configs(BaseSettings):
|
||||
USERNAME: str = ""
|
||||
PASSWORD: str = ""
|
||||
PORT: int = 0
|
||||
SEND: bool = False
|
||||
SEND: bool = 0
|
||||
|
||||
@property
|
||||
def is_send(self):
|
||||
return bool(self.SEND)
|
||||
|
||||
@classmethod
|
||||
def as_dict(cls):
|
||||
def as_dict(self):
|
||||
return dict(
|
||||
host=cls.EMAIL_HOST,
|
||||
port=cls.EMAIL_PORT,
|
||||
username=cls.EMAIL_USERNAME,
|
||||
password=cls.EMAIL_PASSWORD,
|
||||
host=self.HOST,
|
||||
port=self.PORT,
|
||||
username=self.USERNAME,
|
||||
password=self.PASSWORD,
|
||||
)
|
||||
|
||||
model_config = SettingsConfigDict(env_prefix="EMAIL_")
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
from redmail import EmailSender
|
||||
from typing import List, Optional, Dict
|
||||
from pydantic import BaseModel
|
||||
from config import Configs
|
||||
from contextlib import contextmanager
|
||||
from .config import email_configs
|
||||
|
||||
|
||||
class EmailSendModel(BaseModel):
|
||||
@@ -23,11 +23,10 @@ class EmailSession:
|
||||
|
||||
def send(self, params: EmailSendModel) -> bool:
|
||||
"""Send email using this session."""
|
||||
if not Configs.is_send:
|
||||
if not email_configs.is_send:
|
||||
print("Email sending is disabled", params)
|
||||
return False
|
||||
|
||||
receivers = [Configs.USERNAME]
|
||||
receivers = [email_configs.USERNAME]
|
||||
self.email_sender.send(
|
||||
subject=params.subject,
|
||||
receivers=receivers,
|
||||
@@ -53,7 +52,7 @@ class EmailService:
|
||||
@contextmanager
|
||||
def new_session(cls):
|
||||
"""Create and yield a new email session with active connection."""
|
||||
email_sender = EmailSender(**Configs.as_dict())
|
||||
email_sender = EmailSender(**email_configs.as_dict())
|
||||
session = EmailSession(email_sender)
|
||||
try:
|
||||
email_sender.connect()
|
||||
|
||||
Reference in New Issue
Block a user