Website contact form endpoint
This commit is contained in:
@@ -19,7 +19,14 @@ class EmailService:
|
||||
template_dir = os.path.join(os.path.dirname(__file__), '..', 'templates')
|
||||
self.jinja_env = Environment(loader=FileSystemLoader(template_dir))
|
||||
|
||||
async def send_email(self, to_email: str, subject: str, template_name: str, template_vars: dict):
|
||||
async def send_email(
|
||||
self,
|
||||
to_email: str,
|
||||
subject: str,
|
||||
template_name: str,
|
||||
template_vars: dict,
|
||||
reply_to: str | None = None,
|
||||
):
|
||||
# Render the template
|
||||
template = self.jinja_env.get_template(template_name)
|
||||
html_content = template.render(**template_vars)
|
||||
@@ -29,6 +36,8 @@ class EmailService:
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = f"{self.from_name} <{self.from_email}>"
|
||||
msg['To'] = to_email
|
||||
if reply_to:
|
||||
msg['Reply-To'] = reply_to
|
||||
|
||||
# Attach HTML content
|
||||
html_part = MIMEText(html_content, 'html')
|
||||
@@ -45,4 +54,4 @@ class EmailService:
|
||||
# In production, use logging
|
||||
|
||||
|
||||
email_service = EmailService()
|
||||
email_service = EmailService()
|
||||
|
||||
Reference in New Issue
Block a user