Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for sending html mails #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.db.models.query import QuerySet
from django.conf import settings
from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives
from django.core.urlresolvers import reverse
from django.template import Context
from django.template.loader import render_to_string
Expand Down Expand Up @@ -316,11 +317,21 @@ def send_now(users, label, extra_context=None, on_site=True, sender=None):
'message': messages['full.txt'],
}, context)

if(messages['full.html']):
html_body = render_to_string('notification/email_body.html', {
'message': messages['full.html'],
}, context)

notice = Notice.objects.create(recipient=user, message=messages['notice.html'],
notice_type=notice_type, on_site=on_site, sender=sender)

if should_send(user, notice_type, "1") and user.email and user.is_active: # Email
recipients.append(user.email)
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)

msg = EmailMultiAlternatives(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)
msg.attach_alternative(html_body, "text/html")
msg.send()
#send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, recipients)

# reset environment to original language
activate(current_language)
Expand Down