first commit
This commit is contained in:
9
api_services/email/config.py
Normal file
9
api_services/email/config.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from redmail import EmailSender
|
||||
from api_configs import EmailConfig
|
||||
|
||||
email_sender = EmailSender(
|
||||
host=EmailConfig.EMAIL_HOST,
|
||||
port=587,
|
||||
username=EmailConfig.EMAIL_USERNAME,
|
||||
password=EmailConfig.EMAIL_PASSWORD,
|
||||
)
|
||||
31
api_services/email/service.py
Normal file
31
api_services/email/service.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from .config import email_sender
|
||||
|
||||
|
||||
def send_email(
|
||||
subject: str,
|
||||
receivers: list,
|
||||
text: str = "",
|
||||
html: str = "",
|
||||
cc: list = None,
|
||||
bcc: list = None,
|
||||
headers: dict = None,
|
||||
attachments: dict = None,
|
||||
) -> bool:
|
||||
try:
|
||||
email_sender.connect()
|
||||
email_sender.send(
|
||||
subject=subject,
|
||||
receivers=receivers,
|
||||
text=text,
|
||||
html=html,
|
||||
cc=cc,
|
||||
bcc=bcc,
|
||||
headers=headers or {},
|
||||
attachments=attachments or {},
|
||||
)
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"Error raised at email send :{e}")
|
||||
finally:
|
||||
email_sender.close()
|
||||
return False
|
||||
Reference in New Issue
Block a user