我正在尝试使用Pylons 1.0设置TurboMail 3
跟随docs here
我已将此代码添加到development.ini
[DEFAULT]
...
mail.on = true
mail.manager = immediate
mail.transport = smtp
mail.smtp.server = localhost
我的app_globals.py看起来像这样:
"""The application's Globals object"""
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
class Globals(object):
def __init__(self, config):
self.cache = CacheManager(**parse_cache_config_options(config))
from turbomail.adapters import tm_pylons
tm_pylons.start_extension()
我的控制器有这个方法:
def submit(self):
message = Message("from@example.com", "to@example.com", "Hello World")
message.plain = "TurboMail is really easy to use."
message.send()
问题是,当调用message.send()时,我得到了这个错误:
MailNotEnabledException: An attempt was made to use a facility of the TurboMail framework but outbound mail hasn't been enabled in the config file [via mail.on]
我不知道我错过了什么?根据文档,这一切似乎都是对的!
谢谢
发布于 2010-08-12 08:18:33
Pylons 1.0对配置存储在全局对象中的方式(以及何时)进行了几个向后不兼容的更改。在这种情况下,在实例化Globals对象时不再加载配置。相反,您必须将您的代码更改为以下代码:
import atexit
from turbomail import interface
from turbomail.adapters import tm_pylons
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
class Globals(object):
def __init__(self, config):
self.cache = CacheManager(**parse_cache_config_options(config))
atexit.register(tm_pylons.shutdown_extension)
interface.start(tm_pylons.FakeConfigObj(config))
上面的代码(atexit和interface.start)正是start_extension()代码所做的事情。
我将发布一个更新的TurboMail,允许将配置作为参数传递给start_extension(),它应该会以一种更合理的方式澄清这一点。
https://stackoverflow.com/questions/3458344
复制相似问题