Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:dstegelman/django-mail-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
dstegelman committed Sep 13, 2017
2 parents ea792c9 + 621899d commit 6785bac
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
- DJANGO_VERSION=Django==1.8
- DJANGO_VERSION=Django==1.9
- DJANGO_VERSION=Django==1.10
- DJANGO_VERSION=Django==1.11

# command to install dependencies
install:
Expand Down
1 change: 1 addition & 0 deletions mailqueue/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MailerAdmin(admin.ModelAdmin):
search_fields = ['to_address', 'subject', 'app', 'cc_address', 'bcc_address', 'reply_to']
actions = ['send_failed']
inlines = [AttachmentInline]
date_hierarchy = "created"

def send_failed(self, request, queryset):
emails = queryset.filter(sent=False)
Expand Down
15 changes: 13 additions & 2 deletions mailqueue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


from django.conf import settings
from django.core.files.base import ContentFile
from django.core.mail import EmailMultiAlternatives
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
Expand Down Expand Up @@ -69,8 +70,18 @@ def add_attachment(self, attachment):
if self.pk is None:
self._save_without_sending()

Attachment.objects.create(email=self, file_attachment=attachment,
original_filename=attachment.file.name.split('/')[-1])
original_filename = attachment.file.name.split('/')[-1]
file_content = ContentFile(attachment.read())

new_attachment = Attachment()
new_attachment.file_attachment.save(original_filename, file_content, save=False)
new_attachment.email = self
new_attachment.original_filename = original_filename
try:
new_attachment.save()
except Exception as e:
logger.error(e)
new_attachment.file_attachment.delete()

def _save_without_sending(self, *args, **kwargs):
"""
Expand Down

0 comments on commit 6785bac

Please sign in to comment.