TurboMail 3 with Pylons 1.0 - MailNotEnabledException

I am trying to configure TurboMail 3 using Pylons 1.0

Following the docs here

I added this to development.ini

[DEFAULT]
...
mail.on = true
mail.manager = immediate 
mail.transport = smtp 
mail.smtp.server = localhost

and my app_globals.py looks like this:

"""The application 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:

def 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 get this error when calling 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]

I don’t know what I am missing here? All this seems to be correct according to the docs!

thank

+3
source share
1 answer

Pylons 1.0 made several backward incompatible changes in how (and when) the configuration is stored in a global object. In this case, the configuration no longer loads when the Globals object is created. 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))

(atexit interface.start) - , start_extension().

TurboMail, start_extension(), .

+3

Source: https://habr.com/ru/post/1759122/


All Articles