alternative-backend-service/meetings/email_service.py
saani 1fc91d5949 feat: enable meetings app and simplify development configuration
- Enable meetings app in INSTALLED_APPS and add URL routing
- Switch from PostgreSQL to SQLite for default database configuration
- Remove meetings directory from .gitignore
- Move API root endpoint from users app to main URL configuration
- Remove HIPAA-specific email and compliance settings (EMAIL_ENCRYPTION_KEY, HIPAA_EMAIL_CONFIG, BAA_VERIFICATION)
- Add SITE_NAME and ENCRYPTION_KEY environment variables
- Regenerate initial user migrations

These changes simplify the development setup by using SQLite as the default database and removing complex compliance configurations while enabling the core meetings functionality.
2025-11-23 00:19:26 +00:00

90 lines
3.4 KiB
Python

from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.utils.html import strip_tags
from django.conf import settings
class EmailService:
@staticmethod
def send_admin_notification(appointment):
subject = f"New Appointment Request from {appointment.full_name}"
context = {
'appointment': appointment,
'preferred_dates': appointment.get_preferred_dates_display(),
'preferred_times': appointment.get_preferred_time_slots_display(),
'admin_dashboard_url': f"{settings.FRONTEND_URL}/admin/appointments" if hasattr(settings, 'FRONTEND_URL') else '/admin/'
}
html_content = render_to_string('emails/admin_notification.html', context)
text_content = strip_tags(html_content)
admin_email = getattr(settings, 'ADMIN_EMAIL', 'hello@attunehearttherapy.com')
try:
email_msg = EmailMultiAlternatives(
subject,
text_content,
settings.DEFAULT_FROM_EMAIL,
[admin_email]
)
email_msg.attach_alternative(html_content, "text/html")
email_msg.send()
return True
except Exception as e:
print(f"Failed to send admin notification: {e}")
return False
@staticmethod
def send_appointment_scheduled(appointment):
subject = "Your Appointment Has Been Scheduled"
context = {
'appointment': appointment,
'scheduled_datetime': appointment.formatted_scheduled_datetime,
'user_dashboard_url': f"{settings.FRONTEND_URL}/dashboard" if hasattr(settings, 'FRONTEND_URL') else '/dashboard/'
}
html_content = render_to_string('emails/appointment_scheduled.html', context)
text_content = strip_tags(html_content)
try:
email_msg = EmailMultiAlternatives(
subject,
text_content,
settings.DEFAULT_FROM_EMAIL,
[appointment.email]
)
email_msg.attach_alternative(html_content, "text/html")
email_msg.send()
return True
except Exception as e:
print(f"Failed to send scheduled notification: {e}")
return False
@staticmethod
def send_appointment_rejected(appointment):
subject = "Update on Your Appointment Request"
context = {
'appointment': appointment,
'rejection_reason': appointment.rejection_reason or "No specific reason provided.",
'user_dashboard_url': f"{settings.FRONTEND_URL}/dashboard" if hasattr(settings, 'FRONTEND_URL') else '/dashboard/'
}
html_content = render_to_string('emails/appointment_rejected.html', context)
text_content = strip_tags(html_content)
try:
email_msg = EmailMultiAlternatives(
subject,
text_content,
settings.DEFAULT_FROM_EMAIL,
[appointment.email]
)
email_msg.attach_alternative(html_content, "text/html")
email_msg.send()
return True
except Exception as e:
print(f"Failed to send rejection notification: {e}")
return False