generating emails from Python

Michele Simionato michele.simionato at gmail.com
Thu Oct 7 16:57:39 CEST 2004


Benjamin Niemann <b.niemann at betternet.de> wrote in message news:<ck37il$v0j$1 at online.de>...
> 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")
>      outer.attach(part)
> 
>      part = MIMEText(your_html_message, "html", "iso-8859-1")
>      outer.attach(part)

Thank you! I guess I was missing the "alternative" option.
It seems to work, at least I tried it with Pine and Mozilla mail, 
I will do further checking.


            Michele Simionato



More information about the Python-list mailing list