Closed dvuckovic closed 2 years ago
If a custom Content-Disposition header is defined for an attachment, it will be ignored by an email client, because the same header has already been implicitly defined for the same attachment.
Content-Disposition
Pigging back on an example from the docs:
message = MessageSchema( subject='Fastapi-Mail module', recipients=recipients, html="<img src='cid:logo_image'>", subtype='html', attachments=[ { "file": "/path/to/file.png", "headers": { "Content-ID": "<logo_image@localhost>", # This will be ignored. "Content-Disposition": "inline; filename=\"file.png\"" }, "mime_type": "image", "mime_subtype": "png", } ], )
This results in the following header for the attachment part:
--===============2467096897246519167== Content-Type: image/png MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*=UTF8''logo.png Content-Disposition: inline; filename="logo.png" Content-ID: <logo_image@localhost>
Consider checking if Content-Disposition header has been explicitly defined for an attachment, before implicitly adding it to its part. Relevant part of the code: https://github.com/sabuhish/fastapi-mail/blob/a95697251dd26804bc8ff3fe3e426a7f5723cf6a/fastapi_mail/msg.py#L66
This problem has been already mentioned in a closed issue, but perhaps was overlooked: https://github.com/sabuhish/fastapi-mail/issues/92#issuecomment-1017488844
Hi, good point, right it is ignored if not specified. Thanks for catching this behavior and making PR for this, I appreciate your help.
If a custom
Content-Disposition
header is defined for an attachment, it will be ignored by an email client, because the same header has already been implicitly defined for the same attachment.Pigging back on an example from the docs:
This results in the following header for the attachment part:
Consider checking if
Content-Disposition
header has been explicitly defined for an attachment, before implicitly adding it to its part. Relevant part of the code: https://github.com/sabuhish/fastapi-mail/blob/a95697251dd26804bc8ff3fe3e426a7f5723cf6a/fastapi_mail/msg.py#L66This problem has been already mentioned in a closed issue, but perhaps was overlooked: https://github.com/sabuhish/fastapi-mail/issues/92#issuecomment-1017488844