我正试着用塔架1.0安装涡轮邮件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("[email protected]", "[email protected]", "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))
上面的(ATEXT和接口.START)正是StaskExuthSudio()代码所做的。
我将发布一个更新的TurboMail,以允许将配置作为参数传递给start_extension(),这样可以更理智地清除这个问题。