Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Content-Disposition Header Gets Ignored #128

Closed
dvuckovic opened this issue Jun 28, 2022 · 1 comment
Closed

Content-Disposition Header Gets Ignored #128

dvuckovic opened this issue Jun 28, 2022 · 1 comment

Comments

@dvuckovic
Copy link
Contributor

dvuckovic commented Jun 28, 2022

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:

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:

part.add_header('Content-Disposition', 'attachment', filename=filename)

This problem has been already mentioned in a closed issue, but perhaps was overlooked: #92 (comment)

@sabuhish
Copy link
Owner

Hi, good point, right it is ignored if not specified. Thanks for catching this behavior and making PR for this, I appreciate your help.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants