mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-01 03:12:26 +02:00
27 lines
854 B
Python
27 lines
854 B
Python
import html2text
|
|
from django.core import mail
|
|
from django.template.loader import render_to_string
|
|
from django.utils.html import strip_tags
|
|
|
|
from la_chariotte import settings
|
|
|
|
|
|
def send_order_confirmation_mail(order):
|
|
template_name = "mail/order_confirm_mail.html"
|
|
|
|
subject = (
|
|
f"[{settings.PROJECT_NAME}] Votre commande pour «{order.grouped_order.name}»"
|
|
)
|
|
html_message = render_to_string(
|
|
template_name, {"order": order, "base_url": settings.BASE_URL}
|
|
)
|
|
|
|
# create plain message text from html
|
|
plain_message = html2text.html2text(html_message)
|
|
# do not render the logo link
|
|
plain_message = plain_message[plain_message.rfind("Merci,") :]
|
|
|
|
from_email = settings.DEFAULT_FROM_EMAIL
|
|
to = order.author.email
|
|
|
|
mail.send_mail(subject, plain_message, from_email, [to], html_message=html_message)
|