本文介绍了Turbomail 与 Pyramid 的集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我需要一种从 Pyramid 应用程序发送电子邮件的方法.我知道 pyramid_mailer,但它的消息类别似乎相当有限.我不明白是否可以使用模板编写来自 pyramid_mailer 的消息来生成电子邮件的正文.此外,我还没有看到任何关于是否支持富文本,或者是否只是简单的纯文本.

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.

以前,我在 Pylons 框架中使用 Turbomail.不幸的是,似乎没有任何适用于 TurboMail for Pyramid 的适配器.我知道 TurboMail 可以扩展到其他框架,但我什至不知道从哪里开始这样的任务.有没有人为 Pyramid 编写了一个适配器,或者可以指出我需要这样做的正确方向吗?

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?

推荐答案

我无法回答您的 Turbomail 问题,只能说我听说它在 Pyramid 中运行良好.

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

关于 pyramid_mailer,完全有可能使用相同的子系统来渲染您的电子邮件,让金字塔渲染您的所有模板.

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)

此外,pyramid_mailer Message 对象基于 lamson MailResponse 对象,该对象稳定且经过良好测试.

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

通过为 Message 类指定 bodyhtml 构造函数参数,您可以创建包含纯文本正文和 html 的邮件.

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)

这篇关于Turbomail 与 Pyramid 的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 13:51