allyourcode
allyourcode

Reputation: 22623

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?

Upvotes: 12

Views: 2337

Answers (3)

Ehsan
Ehsan

Reputation: 41

As I experienced, Email is more probable to be recognized as spam when you use Message.

Upvotes: 0

Ross
Ross

Reputation: 1033

Please see the following qoute from http://docs.python.org/2/library/email

A new subpackage email.mime was added and all the version 3 email.MIME* modules were renamed and situated into the email.mime subpackage. For example, the version 3 module email.MIMEText was renamed to email.mime.text.

Note that the version 3 names will continue to work until Python 2.6.

Upvotes: 0

allyourcode
allyourcode

Reputation: 22623

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.

Upvotes: 4

Related Questions