How to create an email with embedded images that is compatible with the most mail clients

I’ve had success with exactly the same headers as you’re using, with the following differences: Embedded is not a valid value for the Content-Disposition header. attachment should be fine. inline should also be fine, though I’ve usually seen attachment for multipart/related embedded images. The value of the Content-ID header is supposed to be in the … Read more

How to set MimeBodyPart ContentType to “text/html”?

Call MimeMessage.saveChanges() on the enclosing message, which will update the headers by cascading down the MIME structure into a call to MimeBodyPart.updateHeaders() on your body part. It’s this updateHeaders call that transfers the content type from the DataHandler to the part’s MIME Content-Type header. When you set the content of a MimeBodyPart, JavaMail internally (and … Read more

Add mime type to HTML link

Time to answer my own question. This is a really old question and it probably wasn’t possible at the time but lots has changed since then. The HTML5 spec added the download attribute: <a href=”https://stackoverflow.com/questions/2110269/hugepdf.pdf” download>Download file</a> This will do exactly what I need, tell the browser to download the file instead of opening it. … Read more

Maximum length of a MIME Content-Type header field?

I hope I havn’t misread, but it looks like the length is max 127/127 or 255 total. RFC 4288 has a reference in 4.2 (page 6): Type and subtype names MUST conform to the following ABNF: type-name = reg-name subtype-name = reg-name reg-name = 1*127reg-name-chars reg-name-chars = ALPHA / DIGIT / “!”https://stackoverflow.com/”#”https://stackoverflow.com/”$”https://stackoverflow.com/”&”https://stackoverflow.com/”.”https://stackoverflow.com/”+”https://stackoverflow.com/”-“https://stackoverflow.com/”^”https://stackoverflow.com/”_” It is not … Read more

What rules apply to MIME boundary?

The syntax of a boundary is: boundary := 0*69<bchars> bcharsnospace bchars := bcharsnospace / ” ” bcharsnospace := DIGIT / ALPHA / “‘” / “(” / “)” / “+” / “_” / “,” / “-” / “.” / “/” / “:” / “=” / “?” And the body of a multipart entity has the syntax … Read more

MIMEMultipart, MIMEText, MIMEBase, and payloads for sending email with file attachment in Python

E-mail messages An e-mail message consists of headers (e.g. “From”, “To”, “Subject” etc.) and body (see RFC 822, section 3.1). The body of the message is, by default, treated as plain ASCII text. MIME (RFC 2045, RFC 2046, RFC 2047, RFC 2048, RFC 2049) defines extensions which allow specifying different types of email content. One … Read more

Which MIME type is correct for the .exe file?

application/vnd.microsoft.portable-executable is a registered MIME type and its description matches what you want to use it for. The x- prefix in application/x-msdownload indicates that it is experimental so it should generally be avoided: Especially if something standard is available as it in in this case. application/octet-stream is for arbitary collections of bytes. It does match … Read more

tech