mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
Raise NotSupportedByMandrillError for unsupported attachment mimetypes.
This commit is contained in:
@@ -226,6 +226,18 @@ class DjrillBackend(BaseEmailBackend):
|
||||
if mimetype is None:
|
||||
mimetype = DEFAULT_ATTACHMENT_MIME_TYPE
|
||||
|
||||
# Mandrill silently filters attachments with unsupported mimetypes.
|
||||
# This can be confusing, so we raise an exception instead.
|
||||
(main, sub) = mimetype.lower().split('/')
|
||||
attachment_allowed = (
|
||||
main == 'text' or main == 'image'
|
||||
or (main == 'application' and sub == 'pdf'))
|
||||
if not attachment_allowed:
|
||||
raise NotSupportedByMandrillError(
|
||||
"Invalid attachment mimetype '%s'. Mandrill only supports "
|
||||
"text/*, image/*, and application/pdf attachments."
|
||||
% mimetype)
|
||||
|
||||
return {
|
||||
'type': mimetype,
|
||||
'name': filename or "",
|
||||
|
||||
Reference in New Issue
Block a user