Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install mailmanager

How to install MailManager

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install mailmanager
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0.6 Available View build log
1.0.4 Available View build log
Windows (64-bit)
1.0.6 Available View build log
1.0.4 Available View build log
Mac OS X (10.5+)
1.0.6 Available View build log
1.0.4 Available View build log
Linux (32-bit)
1.0.6 Available View build log
1.0.4 Available View build log
Linux (64-bit)
1.0.6 Available View build log
1.0.4 Available View build log
 
License
MIT
Imports
Lastest release
version 1.0.6 on May 23rd, 2012

# MailManager

This set of classes allow to send emails easily with Python.

## The SMTP Server

The server class keeps an open connection to the SMTP server, trying to recover itself if the connection is interrupted (and throw an exception if it can't).

### How to use the server

Simple:

import mailmanager

server = mailmanager.server() server.set_host("localhost") server.set_port(25) server.set_ssl(False) server.set_username("username@domain.tld") server.set_password("$ecretPa$$w0rd")

try:
server.connect() server.sendmail("from@address", "to@address", "message") server.disconnect()
except Exception, e:
msg, err, exc = e.args print "Server unavailable (%s)" % msg

## The Message

The message class creates an email from known parameters. The result is a string that can be sent through the server class or directly to SMTP.

### How to create a simple multipart message

It's simple, too:

import mailmanager

msg = mailmanager.message() msg.set_mail_from("smtp.sender@address.org") msg.set_from_name("Shown Sender Name") msg.set_from_mail("origin@email.org") msg.set_sender_name("Real Sender Name") msg.set_sender_mail("sender@email.org") msg.set_to_name("Recipient Name") msg.set_to_mail("destination@email.org") msg.set_subject("This is the message subject")

msg.add_part("This is a text content", "plain") msg.add_part("<html><body><h1>This is HTML</h1></body></html>")

### How to add an attachment to a message

This library handles attachments. You just need to declare it.

msg.add_attachment("/path/to/attachment.png")

### How to add an image to an HTML message

Add it to your HTML code:

<img src="cid:image1.png" alt="" />

Notice the "cid:" part. It's not chosen randomly.

Then, open your image file and load the content as binary:

fp = open("/path/to/your/image", "rb") content = fp.read() fp.close()

In your HTML message, add the image and assign the name:

m.add_image("image1.png", content)

That's all.

### How to get parameters to send an email:

The message must be converted to string. Also, there are two helpers to retrieve the sender and the recipient:

s = mailmanager.server() s.connect() s.sendmail(msg.sender(), msg.recipient(), msg.as_string()) s.disconnect()

## Source

https://github.com/rfc83/mailmanager-python

Subscribe to package updates

Last updated May 23rd, 2012

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.