I am using MailKit to read e-mails and save the attachments. That worked fine so far, but I now get emails with attachments from a certain sender, the attachments of which are not seen by MailKit. When is open the e-mails in Outlook, i see that they have attachments, but when debugging my code, message.Attachments list is empty. This is how the MIME info of the attachment in plain text:
----boundary_1_b64b98fa-ae83-44ef-b9e0-90211c2ee383
Content-Type: application/octet-stream; name=202207807Layout.pdf
Content-Transfer-Encoding: base64
What is the problem here and how to solve it?
Your e-mail mime part seems to be missing the following header:
Content-Disposition: attachment; filename="202207807Layout.pdf"
Unfortunately, e-mail isn't as strictly standardized as we developers would like it to be. The relevant RFC says that
Content-Disposition is an optional header field. In its absence, the MUA may use whatever presentation method it deems suitable.
In other words, if the header is not present, it's perfectly legal for one mail client to treat it as an "attachment" and for another to treat it, for example, as "inline content" (and for a third one to "guess" based on various heuristics).
If you cannot change how the sender creates their e-mail, an alternative on the receiving side would be to loop through all mime parts (I'm sure Mailkit offers some way to do that) and manually extract mime parts with a content type of application/octet-stream and a name ending in .pdf
.