53. Sending emails to users after finishing payment
from django.core.mail import send_maildef send_purchase_email(order) :
email = order.client.email
subject = f"Order Approved {order.id}"
items_summary = '\n'.join([
f"Product: {item.itemstock.product.name}, Unitary Price: R$ {item.itemstock.product.price}, Size: {item.itemstock.size}, Quantity: {item.quantity}, Color: {item.itemstock.color.name}, Total product price: R$ {item.total_price}"
for item in order.items
])
body = f"""Congratulations! Your order was approved.
Order ID: {order.id}
FInal order price: R$ {order.total_cost}
Order Content:
{items_summary}
Total Quantity: {order.total_quantity}"""
sender = "dantenavaza2005@gmail.com"
send_mail(subject, body, sender, [email]) #? email must be in list
Previous52. Configuring email sending in Django - password resetNext54. Creating a team and a page to manage the store
Last updated