Added attachments

This commit is contained in:
2018-02-26 18:13:02 -05:00
parent fca60d4376
commit 9a48e3f724
6 changed files with 84 additions and 7 deletions

View File

@ -1,8 +1,9 @@
import mimetypes
from django.db.models import Q
from django.core.mail import EmailMessage
from django.core.management.base import BaseCommand
from django.utils import timezone
from django.utils.html import strip_tags
from OACPL import settings
from OACPL.utils import url_fix_render_to_string
@ -21,6 +22,8 @@ class Command(BaseCommand):
print('Sending newsletter: "%s"' % newsletter.subject)
msg = EmailMessage(subject=newsletter.subject, body=url_fix_render_to_string('email.html', {'content': newsletter.body, 'unsubscribe': True}), from_email=settings.EMAIL_HOST_USER, bcc=subscribers)
msg.content_subtype = 'html'
for attachment in newsletter.attachments.all():
msg.attach(attachment.name(), attachment.file.read(), mimetypes.guess_type(attachment.name())[0])
msg.send()
newsletter.sent = True
newsletter.save()