-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathhelpers.py
More file actions
27 lines (21 loc) · 985 Bytes
/
helpers.py
File metadata and controls
27 lines (21 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
def send_mail(context=None, from_email=None, html_file=None, text_file=None, subject=None, to_email=None):
"""
Function to send emails to a particular user.
:param context_data: Site info.
:param from_email: Sender's email.
:param html_file: Email's html content.
:param text_file: Email's text content.
:param subject: Email's subject.
:param to_email: Recipient's email.
"""
from_email = from_email if from_email else settings.DEFAULT_FROM_EMAIL
context["site"] = Site.objects.get_current()
text = render_to_string(text_file, context)
html = render_to_string(html_file, context)
message = EmailMultiAlternatives(subject, text, from_email, [to_email])
message.attach_alternative(html, 'text/html')
message.send(fail_silently=False)