Python: What is the correct MIME type for attaching html file to email

I would encourage you to use a library rather than deal with the -rather unpythonic- built-in mail modules, such as the highly recommended envelopes:

https://tomekwojcik.github.io/envelopes/index.html

install with:

pip install envelopes

Python code:

import os
from envelopes import Envelope

filename = "C:/CHRIS/ServerStatus/Oceaneering_Server_Status.html"

envelope = Envelope(
    from_addr=(me),
    to_addr=(you),
    subject=u'Test',
    text_body=u'Plain text version',
    html_body=html
)
envelope.add_attachment(filename)

envelope.send('smtp.gmail.com', login='secret', password='secret', tls=True)

Leave a Comment