updated services api
This commit is contained in:
29
ServicesApi/Controllers/Email/implementations.py
Normal file
29
ServicesApi/Controllers/Email/implementations.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from send_email import EmailService, EmailSendModel
|
||||
|
||||
|
||||
# Create email parameters
|
||||
email_params = EmailSendModel(
|
||||
subject="Test Email",
|
||||
html="<p>Hello world!</p>",
|
||||
receivers=["recipient@example.com"],
|
||||
text="Hello world!",
|
||||
)
|
||||
|
||||
another_email_params = EmailSendModel(
|
||||
subject="Test Email2",
|
||||
html="<p>Hello world!2</p>",
|
||||
receivers=["recipient@example.com"],
|
||||
text="Hello world!2",
|
||||
)
|
||||
|
||||
|
||||
# The context manager handles connection errors
|
||||
with EmailService.new_session() as email_session:
|
||||
# Send email - any exceptions here will propagate up
|
||||
EmailService.send_email(email_session, email_params)
|
||||
|
||||
# Or send directly through the session
|
||||
email_session.send(email_params)
|
||||
|
||||
# Send more emails in the same session if needed
|
||||
EmailService.send_email(email_session, another_email_params)
|
||||
Reference in New Issue
Block a user