Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turbomail Integration with Pyramid

I am in need of a method to send an email from a Pyramid application. I know of pyramid_mailer, but it seems to have a fairly limited message class. I don't understand if it's possible to write the messages from pyramid_mailer using templates to generate the body of the email. Further, I haven't seen anything regarding whether rich-text is supported, or if it's just simple plain-text.

Previously, I was using Turbomail with the Pylons framework. Unfortunately there doesn't appear to be any adapters available for TurboMail for Pyramid. I know that TurboMail can be extended for additional frameworks, but have no idea where I would even start such a task. Has anyone written an adapter for Pyramid or can point me in the right direction of what would be required to do so?

like image 348
h0st1le Avatar asked Jun 06 '11 22:06

h0st1le


1 Answers

I can't answer your Turbomail questions other than to say that I've heard it works fine with Pyramid.

Regarding pyramid_mailer, it's entirely possible to render your emails using the same subsystem that lets pyramid render all of your templates.

from pyramid.renderers import render

opts = {} # a dictionary of globals to send to your template
body = render('email.mako', opts, request)

Also, the pyramid_mailer Message object is based on the lamson MailResponse object, which is stable and well-tested.

You can create a mail that consists of both a plain text body as well as html, by specifying either the body or html constructor parameters to the Message class.

plain_body = render('plain_email.mako', opts, request)
html_body = render('html_email.mako', opts, request)
msg = Message(body=plain_body, html=html_body)
like image 102
Michael Merickel Avatar answered Oct 07 '22 23:10

Michael Merickel