There is a standard Python module named "email" which you should look at. It can build an email with all the parts, alternates, and attachments you want. Then you send the resulting message using your smtplib code. The email module is large and complex, but reasonably easy to learn (following the documentation examples). It's far, FAR, easier than rolling your message, especially when attachments are needed.