new api service and logic implemented
This commit is contained in:
0
Services/Email/__init__.py
Normal file
0
Services/Email/__init__.py
Normal file
34
Services/Email/send_email.py
Normal file
34
Services/Email/send_email.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from redmail import EmailSender
|
||||
|
||||
from AllConfigs.Email.configs import EmailConfig
|
||||
from AllConfigs.Email.email_send_model import EmailSendModel
|
||||
|
||||
email_sender = EmailSender(**EmailConfig.as_dict())
|
||||
|
||||
|
||||
class EmailService:
|
||||
|
||||
@classmethod
|
||||
def send_email(cls, params: EmailSendModel) -> bool:
|
||||
if not EmailConfig.EMAIL_SEND:
|
||||
print("Email sending is disabled", params)
|
||||
return False
|
||||
try:
|
||||
email_sender.connect()
|
||||
receivers = ["karatay@mehmetkaratay.com.tr"]
|
||||
email_sender.send(
|
||||
subject=params.subject,
|
||||
receivers=receivers,
|
||||
text=params.text + f" : Gonderilen [{str(receivers)}]",
|
||||
html=params.html,
|
||||
cc=params.cc,
|
||||
bcc=params.bcc,
|
||||
headers=params.headers or {},
|
||||
attachments=params.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