h0s*_*1le 5 python pylons turbogears pyramid
我需要一种从Pyramid应用程序发送电子邮件的方法.我知道pyramid_mailer,但似乎有一个相当有限的消息类.我不明白是否可以使用模板从pyramid_mailer编写消息来生成电子邮件的正文.此外,我还没有看到任何关于是否支持富文本,或者它是否只是简单的纯文本.
以前,我使用Turbomail和Pylons框架.不幸的是,似乎没有任何适用于TurboMail for Pyramid的适配器.我知道TurboMail可以扩展到其他框架,但不知道我甚至会在哪里开始这样的任务.有没有人为金字塔写过适配器,或者能指出我需要做什么的正确方向?
我无法回答您的 Turbomail 问题,只能说我听说它与 Pyramid 配合得很好。
关于pyramid_mailer,完全可以使用与金字塔渲染所有模板相同的子系统来渲染您的电子邮件。
from pyramid.renderers import render
opts = {} # a dictionary of globals to send to your template
body = render('email.mako', opts, request)
Run Code Online (Sandbox Code Playgroud)
此外,pyramid_mailer Message 对象基于 lamson MailResponse 对象,该对象稳定且经过良好测试。
您可以通过向 Message 类指定body
或构造函数参数来创建包含纯文本正文和 html 的邮件。html
plain_body = render('plain_email.mako', opts, request)
html_body = render('html_email.mako', opts, request)
msg = Message(body=plain_body, html=html_body)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
954 次 |
最近记录: |