I’m working with Mailgun for sending notification emails when user data exports are ready. The emails contain download links pointing to files hosted on AWS S3.
My current email template looks something like this:
Your export is complete! <a href="s3-bucket-url" download>Click to download</a>
The issue I’m facing is that when users click the link, some files open directly in the browser instead of downloading. I believe this is related to MIME type configuration.
How can I properly configure the MIME type or modify my approach to ensure files are downloaded rather than displayed in the browser? Is this something I need to handle on the AWS side or can it be managed through Mailgun email formatting?
Had this exact issue at my last company with batch report downloads in email campaigns. The browser behavior depends on how S3 serves the file, not your email markup. When you generate S3 URLs, just append response headers as query parameters to override the default. Modify your links to include the response-content-disposition parameter: https://your-bucket.s3.amazonaws.com/file.pdf?response-content-disposition=attachment. Works great if you’re generating presigned URLs programmatically and don’t want to mess with existing S3 objects. Way cleaner than updating metadata on thousands of files.
This isn’t a Mailgun issue - it’s how S3 handles object metadata. You need to set the Content-Disposition header to “attachment; filename=yourfile.ext” when uploading to S3. That’ll force browsers to download instead of displaying the file. For existing objects, use the AWS CLI or SDK to copy them in place with the right headers. I’ve run into this exact problem before and Content-Disposition fixed it completely. The HTML download attribute won’t work here since S3 links are cross-origin.
you can also use presigned URLs with custom response headers - no need to change your existing S3 objects. just generate the presigned URL with ResponseContentDisposition set to ‘attachment’. it’ll override whatever metadata’s already on the file and works great.
totally agree, it’s an aws thing! make sure to set the content-disposition header to ‘attachment’ when u upload files to S3. that way, the browser will prompt a download instead of trying to open it directly. the html download attribute doesn’t work for cross-origin links.