编程语言
首页 > 编程语言> > python-TurboMail 3 with Pylons 1.0-MailNotEnabledException

python-TurboMail 3 with Pylons 1.0-MailNotEnabledException

作者:互联网

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

我不知道我在这里想念什么吗?
根据文档,一切似乎都正确!

谢谢

解决方法:

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

标签:pylons,python
来源: https://codeday.me/bug/20191209/2097306.html