def send_mail(self, subject_template_name, email_template_name, context, from_email, to_email, html_email_template_name=None ): subject = render(subject_template_name, **context) subject = ''.join(subject.splitlines()) body = render(email_template_name, **context) send_email(subject=subject, text=body, html=body, to=[to_email])
def send_email(self, obj): to_email = settings.SITE_EMAIL subject = render(self.mail_subject) html = render( self.mail_template, **{'subscribe': obj} ) if to_email: send_email(subject=subject, text=html, html=html, to=[to_email])
def send_password_mail(self, user, password): html = render(self.password_mail_template, **{ 'user': user, 'password': password }) to_email = self.form.cleaned_data.get('email') subject = render(self.password_mail_subject, ) if to_email: send_email(subject=subject, text=html, html=html, to=[to_email])
def forgotten_cart_send_email_job(*args, **kwargs): from .models import Cart from datetime import timedelta, datetime, timezone cart_id = None try: cart = Cart.objects.get(id=kwargs['cart_id']) if cart.updated.strftime("%Y-%m-%d %H:%M:%S.%f%z") !=\ kwargs['cart_modification_date'] and not kwargs.get('debug'): cart = None else: cart_id = cart.id except: cart = None if cart is not None and cart.user is not None and cart.items.exists(): activate(cart.language) subject = render( 'checkout/forgotten_cart/forgotten_cart_mail_subject.html' ) email = cart.user.email if settings.MEDIA_ROOT in settings.SITE_LOGO: logo_url = settings.MEDIA_URL + settings.SITE_LOGO.split( settings.MEDIA_ROOT)[-1] else: logo_url = settings.SITE_LOGO data = { 'cart': cart, 'host': Site.objects.get(id=settings.SITE_ID), 'logo': logo_url } html = render( 'checkout/forgotten_cart/forgotten_cart_mail.html', **data ) send_email(subject, '', [email], html) mod_date = datetime.strptime( kwargs['cart_modification_date'], "%Y-%m-%d %H:%M:%S.%f%z") cart_for_send_mail = Cart.objects.filter( updated__gt=mod_date, ).exclude(id=cart_id).order_by('updated').first() if cart_for_send_mail and kwargs['run_after'] in\ settings.CART_CHANGED_EMAIL_SEND_AFTER.split(','): modification_date = cart_for_send_mail.updated task_manager.schedule( 'checkout.jobs.forgotten_cart_send_email_job', kwargs={ 'cart_modification_date': modification_date.strftime( "%Y-%m-%d %H:%M:%S.%f%z"), 'cart_id': cart_for_send_mail.id, 'run_after': kwargs['run_after'] }, run_after=modification_date.replace( tzinfo=timezone.utc ).astimezone(tz=None) + timedelta( minutes=int(kwargs['run_after']) ) )
def send_order_created_mail(self, order): to_email = self.form.cleaned_data.get('email') site = get_current_site(self.request) subject = render(self.order_mail_subject, **{ 'order': order, 'site': site }) html = render(self.order_mail_template, **{ 'order': order, 'site': site }) if to_email: send_email(subject=subject, text=html, html=html, to=[to_email]) if getattr(settings, 'SITE_EMAIL', ''): send_email(subject=subject, text=html, html=html, to=[settings.SITE_EMAIL])
def review_product_mail_job(*args, **kwargs): from checkout.models import Order order = Order.objects.get(id=kwargs['order_id']) activate(order.language) subject = render('review_products/subject.html') email = order.get_user_email() if settings.MEDIA_ROOT in settings.SITE_LOGO: logo_url = settings.MEDIA_URL + settings.SITE_LOGO.split( settings.MEDIA_ROOT)[-1] else: logo_url = settings.SITE_LOGO data = { 'order': order, 'host': Site.objects.get_current(), 'logo': logo_url } html = render('review_products/mail.html', **data) if email: send_email(subject, '', [email], html)