When creating Message objects from scratch, you often need to encode the payloads for transport through compliant mail servers. This is especially true for image/* and text/* type messages containing binary data.
The email package provides some convenient encodings in its Encoders module. These encoders are actually used by the MIMEImage and MIMEText class constructors to provide default encodings. All encoder functions take exactly one argument, the message object to encode. They usually extract the payload, encode it, and reset the payload to this newly encoded value. They should also set the Content-Transfer-Encoding: header as appropriate.
Here are the encoding functions provided:
quoted-printable12.2. This is a good encoding to use when most of your payload is normal printable data, but contains a few unprintable characters.
base64. This is a good encoding to use when most of your payload is unprintable data since it is a more compact form than Quoted-Printable. The drawback of Base64 encoding is that it renders the text non-human readable.
8bitas appropriate, based on the payload data.