[Python-Help] SMTP with attachments

Alex Martelli aleax at aleax.it
Thu Apr 11 06:19:29 EDT 2002


On Thursday 11 April 2002 11:34 am, Ezequiel, Justin wrote:
> How do I send an e-mail with attachments?
> I am a newbie so be gentle.

OK, but please don't cross-post so widely -- addressing only one of the
mailing lists you chose would be best.

If you use Python 2.2 (or have installed the separately available email
package), the email package is best.

At:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86674

you'll find an example of attaching all the files in the current directory.

I hope it's reasonably easy for you to edit this recipe if you want to
be more selecting or whatever.  Note that this recipe doesn't SEND
the email, it just BUILDS it (and writes it into a file called 
dirContentsMail); there are other recipes on the Cookbook for
SENDING, e.g.:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52243

(which you can also take as an example of using the older MimeWriter
way of preparing multipart mail, such as mail with attachments, should
you be unable to use the newer email module for whatever reason).


Alex





More information about the Python-list mailing list