django-dbes icon indicating copy to clipboard operation
django-dbes copied to clipboard

dbes.backends.EmailBackend appears to drop email attachments

Open CloudNiner opened this issue 6 years ago • 2 comments

I created an email via:

fp = open('sample.csv', 'rb')
email = EmailMessage(
    'Sample email header',
    'Sample email body',
    settings.DEFAULT_FROM_EMAIL,
    [settings.SEND_EMAIL]
)
filename = 'sample.csv'
email.attach(filename, fp.read(), 'text/csv')
email.send()

An email is properly sent, and I'm able to hit the email URL at /emails/:emailId when the dbes email urls are configured as described in the documentation.

When I navigate to the email url, I only see the sample email body, with no indication that an email is attached. I see the attachment printed to the Django console when I use the django.core.mail.backends.console.EmailBackend instead.

It is likely not necessary or feasible to print the contents of the attachment, but displaying the attachments and their filenames somewhere would be useful.

CloudNiner avatar Mar 16 '18 17:03 CloudNiner

This feature is not supported in dbes, but actually pretty interesting. Thank you for taking the time to write this issue.

I'm lacking time to work on dbes these days, but I'd be happy to review and merge a PR implementing attachments support in dbes.

As an email can have multiple attachments, this would probably mean creating a new EmailAttachment model and lint it to EmailMessage via a ManyToManyKey.

I'm not sure how this should be displayed in the front-end, but this should not be too difficult to decide.

Let me know if you want to work on this, and if you have any questions. Otherwise, I'll leave this issue open in case other dbes users want to contribute.

agateblue avatar Mar 16 '18 21:03 agateblue

Unfortunately I don't have the bandwidth to implement this at the moment either.

Presenting attachments might be a bit tricky, as you'd want to avoid interfering with the HTML of the regular message body. Perhaps a banner across the top or bottom that displays the number of attachments, and expands to show filenames and download links? The download links could be something like /email/:emailId/attachment/:attachmentId if implemented as you describe via a separate related model.

CloudNiner avatar Mar 19 '18 20:03 CloudNiner