Flesh out the email implementation
This commit is contained in:
parent
c1a61730d5
commit
cee708f4d8
4 changed files with 29 additions and 10 deletions
|
|
@ -1,5 +1,5 @@
|
|||
from dataclasses import dataclass, field
|
||||
from email.utils import formatdate, make_msgid
|
||||
import requests
|
||||
from dataclasses import dataclass
|
||||
import abc
|
||||
|
||||
from ..config.email import Email as EmailConfig, EmailAddress
|
||||
|
|
@ -17,10 +17,6 @@ class EmailDTO:
|
|||
text: str
|
||||
# HTML alternate content. (Optional: Textual content is required)
|
||||
html: str | None = None
|
||||
# A unique ID for identifying this Email
|
||||
message_id: str = field(default_factory=make_msgid)
|
||||
# The date that the email was sent
|
||||
date: str = field(default_factory=lambda: formatdate(localtime=True))
|
||||
|
||||
|
||||
class EmailService:
|
||||
|
|
@ -30,12 +26,20 @@ class EmailService:
|
|||
|
||||
|
||||
class BirdEmailServiceImpl(EmailService):
|
||||
BIRD_API_ENDPOINT = 'https://eu1.platform.bird.com/v1/email/messages'
|
||||
|
||||
def __init__(self, config: EmailConfig):
|
||||
self._config = config
|
||||
|
||||
def send_email(self, email: EmailDTO):
|
||||
# TODO: Implement Bird Specific Email sending and Error handling
|
||||
pass
|
||||
payload = {'from': email.sender, 'to': email.to, 'subject': email.subject, 'text': email.text}
|
||||
|
||||
if email.html:
|
||||
payload['html'] = email.html
|
||||
|
||||
headers = {'Authorization': f'Bearer {self._config.bird_api_key.expose_secret()}'}
|
||||
response = requests.post(BirdEmailServiceImpl.BIRD_API_ENDPOINT, json=payload, headers=headers)
|
||||
return response.ok
|
||||
|
||||
|
||||
def get_service(config: EmailConfig) -> EmailService:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue