Replies: 3 comments 12 replies
-
Ah, welcome to the complex and often frustrating world of email charset encodings. The short version is, you'll probably need to contact MailChimp support. It sounds like they're generating not-really-spec-compliant email messages. And while Gmail overlooks the sloppiness, some other clients don't (or rather, they guess wrong about how to interpret the data Mandrill sent). Here's the long version… This is probably the root of your problem: Content-Disposition: attachment; filename="Rechnung - Møl" That's a UTF-8 encoded filename. Why would that be a problem? Because there's nothing that says it's using UTF-8 encoding. (And also because you can't reliably transport raw 8-bit data through SMTP, even in 2022.) Gmail assumes unknown text is in UTF-8 (or maybe has some clever heuristics to identify charset). The Mac mail client probably assumes unknown text is ISO-8859-1, which is why it's displaying the wrong characters. Here's how RFC 2231 says that attachment header should be sent: Content-Disposition: attachment; filename*=utf-8''Rechnung%20-%20M%C3%B8l Notice the So this seems like a bug in how Mandrill is composing the outgoing email. I don't see anything in their API docs that you could use to work around it. (Unfortunately, I can't test it myself, due to MailChimp's policies against providing development access for projects like Anymail.) When you contact their support, it may be helpful to eliminate Anymail and Django from the picture. You can use Anymail's BTW, the other two attachment headers refer to the data that goes into the attachment file itself (but not the attachment's filename). Finally, if that wasn't enough information for you, I came across a helpful 2017 blog post The mess that is attachment filenames that goes into detail on all of this and more. |
Beta Was this translation helpful? Give feedback.
-
Ah, I was thinking you might need the raw API request (not response), which should be in a section starting |
Beta Was this translation helpful? Give feedback.
-
I signed up for a trial account, and have confirmed this is a bug in Mandrill itself (not Anymail, and not any particular email client). Correction: it only affects attachment filenames, not other fields. [An earlier version of this comment incorrectly claimed Mandrill was not using RFC 2047 encoding in the Subject, To, Cc, and Bcc headers. They are. It's only the attachment filename field that is improperly sent as raw UTF-8. My apologies for the confusion.] Bug: Mandrill's /messages/send API does not properly handle non-ASCII characters in attachment filenames. As a result, many email clients will display incorrect garbled characters in their place. Specifically, Mandrill does not use required RFC 2231 encoding for the filename parameter in an attachment part's Content-Disposition header. Instead, Mandrill appears to place the raw UTF-8 bytes from the API request directly into the header. The RFC 5322 email message format doesn't allow that. Non-ASCII characters cannot appear in header fields; they must use an encoding that specifies the character set. Faced with the non-standard message Mandrill generates, email clients can interpret the non-ASCII bytes in any way they choose. Gmail appears to guess correctly that they are UTF-8. Apple Mail appears to guess incorrectly that they are ISO-8859-1, resulting in garbled text. Other email clients might strip out the non-ASCII bytes, incorrectly guess other character sets, or (theoretically) even crash. Unless you hear back from Mandrill that they've fixed the problem, I'll probably add a note about this to the "quirks" section in Anymail's Mandrill docs. A possible workaround is to use Django's SMTP EmailBackend (rather than Anymail) with Mandrill's SMTP integration, which would avoid their buggy /messages/send API. Django uses Python's standard email package under the hood, which does follow the standards for header encoding. (Incidentally, the Mandrill SMTP integration docs specifically call out the need to use RFC 2047 header encoding for things like Subject. Attachment filenames also need to be encoded, though they use a different standard.) |
Beta Was this translation helpful? Give feedback.
-
Hey Anymailnauts :)
We have recently introduced sending attachments to our customers. Specifically, receipts as pdfs. We have encountered one small problem regarding Macs Mail Client.. (who would have thought..)
Our filename contains special characters, as the german
ö
,ä
andü
or the danishø
,æ
andå
.Gmail correctly shows the filename, without issues, Office365 also does, just not while using the native Mac client. Sadly, a lot of customers use tha client, and we want to try to support it. Hoewever, I am a bit lost into why this happens. I have tried to investigate the email that got sent using mandrill in gmail a bit. And I found this:
This is how it looks in the Mac Mail Client, which problably doesnt support base64.
Any tip for me, on how to solve this? Can we set
Content-Transfer-Encoding
somehow?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions