Merge pull request #84 from Schlabonski/issue83

save mail before trying to send
v1-0-stable
Christian Merten 8 years ago committed by GitHub
commit 7519cb3971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,7 @@ from django.core.exceptions import ValidationError
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext from django.utils.translation import ugettext
from .mailutils import send, get_content, SENT, PARTLY_SENT, mail_root from .mailutils import send, get_content, NOT_SENT, SENT, PARTLY_SENT, mail_root
from utils import RestrictedFileField from utils import RestrictedFileField
import os import os
@ -72,17 +72,22 @@ class Message(models.Model):
# remove any underscores from subject to prevent Arne from using # remove any underscores from subject to prevent Arne from using
# terrible looking underscores in subjects # terrible looking underscores in subjects
self.subject = self.subject.replace('_', ' ') self.subject = self.subject.replace('_', ' ')
success = send(self.subject, get_content(self.content), try:
SENDING_ADDRESS, success = send(self.subject, get_content(self.content),
emails, SENDING_ADDRESS,
attachments=attach, emails,
reply_to=self.reply_to.email if self.reply_to else None) attachments=attach,
for a in Attachment.objects.filter(msg__id=self.pk): reply_to=self.reply_to.email if self.reply_to else None)
if a.f.name: if success == SENT or success == PARTLY_SENT:
os.remove(a.f.path) self.sent = True
a.delete() for a in Attachment.objects.filter(msg__id=self.pk):
if success == SENT or success == PARTLY_SENT: if a.f.name:
self.sent = True os.remove(a.f.path)
a.delete()
except Exception as e:
print("Exception catched", e)
success = NOT_SENT
finally:
self.save() self.save()
return success return success

Loading…
Cancel
Save