tylermakin / Multipart MIME Email.md
This is a guide on how to send a properly formatted multipart email. Multipart email strings are MIME encoded, raw text email templates. This method of structuring an email allows for multiple versions of the same email to support different email clients.
// Example Multipart Email: From: sender@example.com To: recipient@example.com Subject: Multipart Email Example Content-Type: multipart/alternative; boundary="boundary-string" --your-boundary Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Plain text email goes here! This is the fallback if email client does not support HTML --boundary-string Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This is the HTML Section!
This is what displays in most modern email clients
--boundary-string--
Different Content-Type Sections
Multipart email strings are composed of sections for each Content-Type version of the email you wish to use. By sending differently formatted versions, you can ensure your recipients are able to see whatever message you are sending, optimized for their email clients’ capabilities.
Content-Type | Description | ||||
---|---|---|---|---|---|
text/html | This allows the use of HTML (
Example use cases of different Content-Type :
The plain text format is a means to send an unformatted copy of an email, without images or styles, that will be readable by everyone. Although HTML makes emails beautiful, plain text makes them functional. In addition to helping prevent your emails from getting caught in the spam filter, a plain text version of your email will allow everyone to see your message, regardless of email client. or settings. HTML formatting allows for the use of web languages (HTML and CSS) to style emails, display images, etc. It is important to always include a plain text version of the email when using HTML because some email clients do not support HTML emails, and some recipients prefer plain text format. HTML format allow for the use of tags such as Titleand styles such as Touch of Gray in your emaill. This format also allows for the use of remote images via links You can send emails specifically formatted to the text/watch-html format to allow for Apple Watch users to view your emails on their devices. The Apple Watch email client has limited support for HTML and is similar in ability to rich text format (see table). Although images are possible in this format, they are quirky and may not display properly. You may test your email by sending it via a service such as the free PutsMail tool and seeing how it appears in your inbox. Services such as this allow the testing of emails without the need for an email API (Mandrill, Mailgun, Amazon SES, etc.) email service provider, or your own email server. Although PutsMail does not allow you to send an entire multipart email as a MIME string (all of the examples in this guide), you can send each section (HTML, plain text, watch) individually by copy/pasting the code for each type individually without the headers. |