generating emails from Python

Benjamin Niemann b.niemann at
Thu Oct 7 13:03:45 CEST 2004

Michele Simionato wrote:
> Is it possible, using email.MIMEMessage, to generate an email with
> both HTML and plain text content, in such a way that:
> 1) it is displayed as HTML if the email client recognizes HTML;
> 2) it is displayed as plain text if the email client is HTML impaired?
> I realize that the answer is most probably no, but one can always hope
yep, you can:

     outer = MIMEMultipart("alternative")
     outer['Subject'] = subject
     outer['To'] = email_to
     outer['From'] = email_from
     outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
     # To guarantee the message ends with a newline
     outer.epilogue = ''

     part = MIMEText(your_plain_message, "plain", "iso-8859-1")

     part = MIMEText(your_html_message, "html", "iso-8859-1")

More information about the Python-list mailing list