A module to send email simply in Python

Update: I've released version 0.3 of the mailer module. See the mailer home page for details and the latest version.

The email and smtplib modules in Python are very powerful, but they're also a bit complex when you just want to send an email.

I wrote the mailer module as a front end to these two modules, in order to make the task of sending email in Python using SMTP as simple as possible.

Below are some examples.

Send a simple plain text email

import mailer mailer message = mailer.Message()

message.From = "me@example.com"

message.To = "you@example.com"

message.Subject = "My Vacation"

message.Body = open("letter.txt", "rb").read() mailer = mailer.Mailer('mail.example.com')

mailer.send(message)

Send an email with an attachment

Message ( )

message. From = "me@example.com"

message. To = "you@example.com"

message. Subject = "My Vacation"

message. Body = open ( "letter.txt" , "rb" ) . read ( )

message. attach ( "picture.jpg" ) message = mailer.message.message.message.message.message. mailer = mailer.Mailer('mail.example.com')

mailer.send(message)

Send an HTML email

Message ( )

message. From = "me@example.com"

message. To = "you@example.com"

message. Subject = "My Vacation"

message. Body = open ( "letter.txt" , "rb" ) . read ( )

message. Html = "" "This email is in <b>HTML</b>.

<a href=" http://example. com ">Here's a link.</a>" "" message = mailer.message.message.message.message.message.http://example. mailer = mailer.Mailer('mail.example.com')

mailer.send(message)

Download the mailer module (zip file).

Edit: Here's the source code of the mailer module.