def send_order_fulfilled_email(sender, instance, *args, **kwargs): if instance.status_tracker.has_changed( 'status') and instance.status == Cart.Status.FULFILLED: order = instance.ordershipping cart_details = order.cart.cartdetail_set.all() #Info needed to send user email email = instance.user.email subject = f"ORDER INVOICE" message = f"Your order has been shipped and an invoice will be provided on delivery. Please log into your account to view details." html_message = loader.render_to_string('email/invoice_email.html', { 'order': order, 'user': instance.user, 'cart_details': cart_details }) msg = EmailMultiAlternatives(subject, message, 'settings.EMAIL_HOST_USER', [email]) msg.attach_alternative(html_message, "text/html") msg.mixed_subtype = 'related' f = 'static/images/road-star-logo.png' fp = open(os.path.join(os.path.dirname(__file__), f), 'rb') msg_img = MIMEImage(fp.read()) fp.close() msg_img.add_header('Content-ID', '<{}>'.format(f)) msg.attach(msg_img) print(msg_img.get_filename()) msg.send()
def email_invoice(req, order_id): order = OrderShipping.objects.get(id=order_id) cart_details = order.cart.cartdetail_set.all() #Info needed to send user email email = req.user.email subject = f"ORDER INVOICE" message = f"Your order has been shipped and an invoice will be provided on delivery. Please log into your account to view details." html_message = loader.render_to_string( 'email/invoice_email.html', { 'order': order, 'user': req.user, 'cart_details': cart_details }) msg = EmailMultiAlternatives( subject, message, 'settings.EMAIL_HOST_USER', [email] ) msg.attach_alternative(html_message, "text/html") msg.mixed_subtype = 'related' f = 'static/images/road-star-logo.png' fp = open(os.path.join(os.path.dirname(__file__), f), 'rb') msg_img = MIMEImage(fp.read()) fp.close() msg_img.add_header('Content-ID', '<{}>'.format(f)) msg.attach(msg_img) print(msg_img.get_filename()) msg.send() return redirect('account')