Send branded HTML emails and harden SMTP2GO webhooks.
Fix campaign stuck on sending under async queue, and stop UUID ValidationError when SMTP2GO tests send "Headers Unavailable".
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
import logging
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.mail import EmailMessage
|
||||
from django.core.mail import EmailMultiAlternatives
|
||||
from django.template.loader import get_template
|
||||
from django.urls import reverse
|
||||
|
||||
from leads.models import Lead
|
||||
from public.email_branding import email_brand_context
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -49,23 +51,25 @@ def notify_admins_of_contact_form(lead: Lead) -> bool:
|
||||
]
|
||||
address = "\n".join(bit for bit in address_bits if bit) or "(none)"
|
||||
|
||||
body = (
|
||||
f"New contact form inquiry from {name}.\n\n"
|
||||
f"Name: {name}\n"
|
||||
f"Email: {email}\n"
|
||||
f"Phone: {phone}\n"
|
||||
f"Address:\n{address}\n\n"
|
||||
f"Message:\n{message}\n\n"
|
||||
f"View in portal: {portal_url}\n"
|
||||
ctx = email_brand_context(
|
||||
name=name,
|
||||
email=email,
|
||||
phone=phone,
|
||||
address=address,
|
||||
message=message,
|
||||
portal_url=portal_url,
|
||||
)
|
||||
text_content = get_template("emails/contact_email.txt").render(ctx)
|
||||
html_content = get_template("emails/contact_email.html").render(ctx)
|
||||
|
||||
mail = EmailMessage(
|
||||
mail = EmailMultiAlternatives(
|
||||
subject=f"New contact form inquiry from {name}",
|
||||
body=body,
|
||||
body=text_content,
|
||||
from_email=settings.DEFAULT_FROM_EMAIL,
|
||||
to=[to_email],
|
||||
reply_to=[contact.email] if contact.email else None,
|
||||
)
|
||||
mail.attach_alternative(html_content, "text/html")
|
||||
try:
|
||||
mail.send(fail_silently=False)
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user