simple example of mimelib? and embedding (not attaching) images in email sent with python.

Barry A. Warsaw barry at zope.com
Tue Aug 14 23:12:35 EDT 2001


>>>>> "S" == Stephen  <shriek at gmx.co.uk> writes:

    S> I've looked through the archives regarding using smtplib and
    S> the numerous MIME related modules for sending email messages
    S> with attachments.  I've found various solutions, some of which
    S> no longer seem to work, and was quite surprised how this
    S> seemingly banal task has caused so much trouble.  However, in
    S> Microsoft Outlook, it's possible to embed image files into the
    S> actual message as opposed to having them attached.  This way,
    S> they display when the recipient views the message.  Just how
    S> does one compose a message like that with Python may I ask?

It's actually fairly easy using mimelib.  Note that

    http://mimelib.sf.net

contains a pretty up-to-date description of the library API, but it is
missing an examples section.  That's on my to do list.

    S> Also if I read between the lines of some posts in the archive,
    S> is it safe to assume that mimelib is the way to go for future
    S> MIME manipulation?

That's the intention.  Guido has given me the green light for adding
mimelib to Python 2.2's standard library, and I intend to work on that
over the next several days.  I've got a few bugs and improvements to
work out, and a little bit more documentation to right, but I think
it's quite useful as is.  I also think it has a flexible enough
architecture to provide room for expansion as time goes on.

One question though: while I original wrote mimelib to handle the
MIME-specific tasks, it really is shaping up to be a general mail
handling library.  "mimelib" might be the wrong name for it.
"maillib" and "emaillib" seem inelegant, and "messagelib" too
generic.  So while mimelib will be able to replace even rfc822.py (at
least at the API level initially, perhaps later at the implementation
level too), we may just have to live with the misnomer, unless someone
can come up with a good -- not too clever, but descriptive -- name.
    
    S> If so, would it be asking too much for a simple example snippet
    S> showing how it is used becaues I can't work out where to start
    S> with it. In fact I'm off to download Mailman in order to read
    S> the source and see how it uses mimelib.  This is overkill on a
    S> par with taking apart your Range Rover in order to learn how
    S> carburetors work.

True.

Have you looked at the unit tests that come with mimelib?  There are
enough examples there to get the basic feel.  For example, look at
test_multipart.py for an example of how to create a MIME message
containing a plain text part and an image attachment.

That's part of the trouble with examples in the documentation: they
can be pretty long-winded.  But that's no excuse for not including
/something/ to give you a feel for how to use it.

Hope that helps,
-Barry




More information about the Python-list mailing list