TurboMail 3与Pylons 1.0 - MailNotEnabledException

时间:2010-08-11 12:45:48

标签: python pylons

我正在尝试使用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]

我不知道我在这里失踪了什么? 根据文档,这一切似乎都是正确的!

由于

1 个答案:

答案 0 :(得分:3)

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(),这应该以更合理的方式清除它。