enricorampazzo's picture
set the email content-transfer-encoding to 8bit to avoid mangled text, added the building name to the email subject line
c8801b5
raw
history blame contribute delete
980 Bytes
from email.message import EmailMessage
from prompts.prompts_manager import Questions
from prompts.prompts_manager import PromptsManager
from repository import Repository
class EmailManager:
def __init__(self, pm: PromptsManager, repository:Repository):
self.pm = pm
self.repository = repository
def create_email(self, answers: dict[Questions, str], pdf_form, filename) -> EmailMessage:
msg = EmailMessage()
msg["Subject"] = (f"Minor work permit for unit {answers[Questions.UNIT_APT_NUMBER]} in "
f"{answers[Questions.BUILDING]}, {answers[Questions.COMMUNITY]}")
msg["From"] = answers[Questions.YOUR_EMAIL]
msg["To"] = "[email protected]"
message = self.repository.send_prompt(self.pm.compose_email(answers), True)["content"]
msg.set_content(message, cte="8bit")
msg.add_attachment(pdf_form, maintype="application", subtype="pdf", filename=filename)
return msg