Whilst working on a project this week I found myself at a stand still when installing and configuring TurboMail with my TurboGears 2.0 application. For the l life of me, I could not get mail to send. I'm writing this up to hopefully help the googlers out there, as well as provide a reference for myself in the future. I imagine once the latest versionn of TurboMail because stable this issue won't be a problem for anyone, but for me... right here, right now... it was.
Please note that this does not go into detail about setting up a TurboGears 2.0 application or advanced TurboMail usage either. For more information on TG2.0 please check out How to install TurboGears 2. Additionally, you should read the documentation for TurboMail 3.0.
Based on the How to install TurboGears 2 article, you should have a working and active virtualenv with a functional TG2 application, and the ability to easy_install via setuptools.
Initially I tried to get TurboMail working by installing it via setup_tools:
(tg2env) ~]$ easy_install TurboMail
Unfortunately, this bailed with the following error:
(tg2env) ~]$ easy_install TurboMail
Searching for TurboMail
Reading http://pypi.python.org/simple/TurboMail/
Reading http://www.topfloor.ca/turbomail/
Reading http://www.python-turbomail.org/
Reading http://trac.orianagroup.com/turbomail/
Best match: TurboMail 2.1
Downloading http://pypi.python.org/packages/source/T/TurboMail/TurboMail-2.1.tar.gz#md5=36087c074e7943e8a352ef6cdd3dc04f
Processing TurboMail-2.1.tar.gz
Running TurboMail-2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-5fgvDC/TurboMail-2.1/egg-dist-tmp-RM4OXA
Traceback (most recent call last):
File "/home/wdierkes/devel/tg2env/bin/easy_install", line 8, in <module>
load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')()
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 1671, in main
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 1659, in with_ei_usage
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 1675, in <lambda>
File "/usr/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 211, in run
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 446, in easy_install
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 476, in install_item
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 655, in install_eggs
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 930, in build_and_install
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 919, in run_setup
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 27, in run_setup
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 63, in run
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 29, in <lambda>
File "setup.py", line 6, in <module>
setup(name='shakedown',
ImportError: No module named turbogears.finddataAs you can see there was a bit of a conflict here, which led me to the fact that the latest stable version of TurboMail in the cheese shop is 2.1. Support for TG2 was added in TurboMail 3.0, so I tried the following:
(tg2env) ~]$ easy_install TurboMail >=3.0
Still... no dice. From the download page I can see that 3.0b1 is the latest 'beta release'. Unfortunately I found that even this version is not compatible with TurboGears 2.0.
So what then?
It turns out that real support for TG2 is in the beta-beta version 0.3b2. At the time of this writing this is only available via a source tarbal
The following steps get TurboMail-0.3b2 installed. Be sure that your virtualenv is active!
(tg2env) ~]$ wget http://www.python-turbomail.org/raw-attachment/wiki/TurboMailDownload/TurboMail-3.0b2.tar.gz (tg2env) ~]$ tar -zxvf TurboMail-3.0b2.tar.gz (tg2env) ~]$ cd TurboMail-3.0b2 (tg2env) TurboMail-3.0b2] $ python setup.py install
We should probably check the basic TurboMail functionality before introducing it to TurboGears:
>>> from turbomail.message import Message >>> from turbomail.control import interface >>> interface.config.update({ ... 'mail.on': True, ... 'mail.provider': 'smtp', ... 'mail.smtp.server': 'localhost' ... }) >>> interface.start(interface.config) >>> message = Message( ... author = "me@localhost", ... to = "wdierkes@5dollarwhitebox.org", ... subject = "Hello from TurboMail 3.0b2", ... plain = "This is a sample message from TurboMail!" ... ) >>> message.send() True >>> interface.stop() >>>
Now you will notice, nothing actually gets sent. This is because by default if you do not specify a 'mail.transport' all messages are sent to '/dev/null'. This helps prevent johnny developers from spamming their entire user base with test emails.
So lets try this again:
>>> from turbomail.message import Message >>> from turbomail.control import interface >>> interface.config.update({ ... 'mail.on': True, ... 'mail.manager': 'immediate', ... 'mail.transport': 'smtp', ... 'mail.provider': 'smtp', ... 'mail.smtp.server': 'localhost', ... }) >>> interface.start(interface.config) >>> message = Message( ... author = "me@localhost", ... to = "wdierkes@5dollarwhitebox.org", ... subject = "Hello from TurboMail 3.0b2", ... plain = "This is a sample message from TurboMail" ... ) >>> message.send() True >>> interface.stop() >>>
At this point, you should have recieved an email... that, or you should atleast see the entry in your mail log referencing the attempt. In my case, my email provider MailTrust came through and actually rejected this email becuase of the sending address 'me@localhost':
Aug 11 12:42:17 wdierkes-linux postfix/smtp[29896]: C710230A8F1: to=<wdierkes@5dollarwhitebox.org>, relay=mx1.emailsrvr.com[98.129.184.3]:25, delay=0.23, delays=0.01/0.03/0.09/0.1, dsn=5.5.2, status=bounced (host mx1.emailsrvr.com[98.129.184.3] said: 504 5.5.2 <me@localhost>: Sender address rejected: need fully-qualified address (in reply to RCPT TO command))
Regardless, the email was sent properly from TurboMail.
As mentioned in the last section, the default settings for TurboMail will not actually send out any mail, but rather route the messages to /dev/null. You simply need to add a few setting to get the transport working.
Please add these configuration to the following files to enable TurboMail support in your TG2 application:
Under the '[DEFAULT'] section, add the following to .ini config file. In my case, this is 'development.ini':
[DEFAULT] # turbomail mail.on = True mail.manager = immediate mail.transport = smtp mail.provider = smtp mail.smtp.server = 127.0.0.1 ...
Please modify settings accordingly for your server environment. Then add the following to the '__init__' funcion in the file './
def __init__(self): from turbomail.adapters import tm_pylons tm_pylons.start_extension()
For clarity, my entire app_globals.py is:
# -*- coding: utf-8 -*- """The application's Globals object""" __all__ = ['Globals'] class Globals(object): def __init__(self): from turbomail.adapters import tm_pylons tm_pylons.start_extension()
With these configurations in place, you should be able to send a message anywhere within your TG2 application.
from turbomail.message import Message msg = Message( author="noreply@5dollarwhitebox.org", to="wdierkes@5dollarwhitebox.org", subject="Message from TurboMail 0.3b2", plain="Test message from TurboMail" ) msg.send()
What do you know, I actually recieved it this time. ;)
TurboMail is a multi-threaded mail delivery subsystem and MIME message generation framework for Python.
TurboGears 2.0 is the next stage in TurboGears development, and provides a solid base on which the future of TurboGears will be built. The 2.0 release does not spell the end of 1.0 support, and while it's new, there are already people using it in production.