I am trying to setup TurboMail 3 with Pylons 1.0
Followed the docs here
I have added this to the development.ini
[DEFAULT]
...
mail.on = true
mail.manager = immediate
mail.transport = smtp
mail.smtp.server = localhost
and my app_globals.py looks like:
"""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()
My controller has this method:
d开发者_C百科ef submit(self):
message = Message("from@example.com", "to@example.com", "Hello World")
message.plain = "TurboMail is really easy to use."
message.send()
The problem is that I am getting this error when message.send() is been called:
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]
I don't know what am I missing here? It all seems right according to the docs!
Thanks
Pylons 1.0 made several backwards-incompatible changes to how (and when) the configuration is stored in a global object. In this case, the configuration is no longer loaded when the Globals object is instantiated. Instead, you will have to change your code to the following:
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))
The above (atexit and interface.start) is exactly what the start_extension() code does.
I'll be releasing an updated TurboMail to allow passing the configuration as an argument to start_extension(), which should clear this up in a more sane way.
精彩评论