diff --git a/.gitignore b/.gitignore index 8bd847a..705abd0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ coverage.xml .coverage __pycache__ .DS_Store -*.sqlite* \ No newline at end of file +*.sqlite* +.vscode/ \ No newline at end of file diff --git a/django_ses_plus/models.py b/django_ses_plus/models.py index e63af36..f1df28c 100644 --- a/django_ses_plus/models.py +++ b/django_ses_plus/models.py @@ -37,7 +37,7 @@ class SendEmailMixin(object): def get_to_email(self): return self.email - def send_email(self, subject, template_path, context, from_email=None, language=None): + def send_email(self, subject, template_path, context, from_email=None, language=None, headers=None): from .tasks import send_email if not DJANGO_SES_PLUS_SETTINGS["SEND_EMAIL"]: return _("Email cannot be sent due to SEND_EMAIL flag in project settings.") @@ -56,7 +56,8 @@ def send_email(self, subject, template_path, context, from_email=None, language= to_email=self.get_to_email(), html_message=html_message, from_email=from_email, - recipient_id=recipient_id + recipient_id=recipient_id, + headers=headers ) if language: diff --git a/django_ses_plus/tasks.py b/django_ses_plus/tasks.py index dc19c88..9d10613 100644 --- a/django_ses_plus/tasks.py +++ b/django_ses_plus/tasks.py @@ -5,28 +5,29 @@ from django_ses_plus import logger from .settings import DJANGO_SES_PLUS_SETTINGS from django.core.files.base import ContentFile -from django.core.mail import send_mail +from django.core.mail import EmailMultiAlternatives from django.utils.translation import ugettext_lazy as _ from .models import SentEmail @shared_task(retry_kwargs=DJANGO_SES_PLUS_SETTINGS["CELERY_TASK_RETRY_KWARGS"]) -def send_email(subject, to_email, html_message, from_email=None, message=None, recipient_id=None): +def send_email(subject, to_email, html_message, from_email=None, message=None, recipient_id=None, headers=None): if not DJANGO_SES_PLUS_SETTINGS["SEND_EMAIL"]: return _("Email cannot be sent due to SEND_EMAIL flag in project settings.") if not from_email: from_email = DJANGO_SES_PLUS_SETTINGS["DEFAULT_FROM_EMAIL"] - send_mail( + email = EmailMultiAlternatives( subject=subject, - message=message, - html_message=html_message, + body=message, from_email=from_email, - recipient_list=[to_email], - fail_silently=False, + to=[to_email], + headers=headers ) + email.attach_alternative(html_message, 'text/html') + email.send() try: SentEmail.objects.create(