Some of the information here may be outdated, please check the book instead

Want to be able to send emails with both plain text and html bodies and even include attachments? Refer to

Using the MultiPart_Mail class documented in the wiki, you can send emails from your controller like this

context=dict(name='John Smith', items=['apples','oranges','bananas'], total = 12.75)

#use views to help create message bodies
message_text = response.render('default/email_template.txt',context)

recipients = ['John Smith <>']
subject = "Your Order Has Shipped"

#get contents of the files to attach
attach1 = _prep_attachment('/path/to/logo.jpg')
attach2 = _prep_attachment('/path/to/special_offers.pdf', 'special offers.pdf')

for recipient in recipients:
    status = MimeMail.send(to=recipient, subject=subject, message_text=message_text, message_html=message_html,
            attachments = [attach1, attach2])
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by web2py - design derived from a theme by the earlybird
The content of this book is released under the Artistic License 2.0 - Modified content cannot be reproduced.