2010-08-11 54 views
3

我試圖建立TurboMail 3塔1.0TurboMail 3塔1.0 - MailNotEnabledException

沿襲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] 

我不知道我缺少什麼嗎? 這一切似乎根據文檔!

由於

回答

3

塔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(),它應該以更爲理智的方式清除它。