msg = MIMEMultipart('alternative')
msg['Subject'] = 'My subject'
msg['From'] = 'foo@example.org'
msg['To'] = 'bar@example.net'
html = """<html>
          <body>
          This is <i>HTML</i>
          </body>
          </html>
"""
text = 'This is HTML'
plain = MIMEText(text, 'plain')
html = MIMEText(html, 'html')
msg.attach(plain)
msg.attach(html)
print(msg.as_string())
Использование python в mutt для создания составных/альтернативных писем