Skip to content
Advertisement

When should I use email.message.Message vs. email.mime.text.MIMEText when constructing an email in Python?

I don’t know a whole lot about the technical details for constructing and sending email (I figure that’s what libraries are for). Seems like both of these classes can be used to construct a basic text email, so which one should I use?

What are the differences between these? When is appropriate to use one vs. the other?

Advertisement

Answer

One difference I found was that MIMEText has the Content-Type header set to something like ‘text/plain’; whereas, Message does not set this header. For me, that’s a good enough reason to default to MIMEText, but I’d be interested to know if there are other differences.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement