We love designing and developing websites, but what really drives us is solving problems and cultivating strong relationships with our clients
Writing an e-mail application with Lamson - I
By : thejaswi
Off late, we've been slightly busy with a 'lot' of new developments on our end and we've not been able to devote attention to the blog. In these busy periods, we tend to forget things faster. One such thing that Shabda recently pointed out that a couple of our applications (client and open source project) were raising exception. Because of the low frequency of these errors, they went unnoticed for quite a few days. We do check e-mail often but we are mostly drowned in our project management tool, Unfuddle. Shabda suggested we open a ticket for every error (with duplicates taken care off) and this way we wouldn't have to distract ourselves scouring multiple sources like mail, Unfuddle etc.
This was a fairly straightforward requirement. Unfuddle has an API and all we have to do is wrap the 500 error handler. We could write the error handler in a separate app and then add it to the INSTALLED_APPS setting and error handler to all the projects. Sounds fine but we should not miss out a single project! It didn't sound like a scalable solution and so we decided to add an e-mail address to the MAIL_ADMINS setting that would open a ticket invoking the Unfuddle API. Not a big difference over the previous solution. This method just saves 1 line of typing over the previous. But the idea of having to learn and use Lamson got us excited!
Lamson is a Python SMTP server written by Zed Shaw that makes e-mail application development not suck! If we hadn't heard of Lamson, we would've probably used Postfix to drop mail to fetchmail and then run a python script to parse the mail and redirect it accordingly. This solution has way too many dependencies and is a configuration hell!
In the coming blog posts, let's write a Lamson powered e-mail app that will open a ticket in the unfuddle project management system through their API. Before we start, I will give away a little secret. You don't have to be a sys-admin or a python expert to write an e-mail app powered by Lamson. It's as easy as writing a simple web app in django.
Installation of Lamson
The Lamson documentation covers how to install Lamson. But we are not going to discuss this very deeply. We'll just use a virtualenv to install it.:
$ virtualenv lamson_env $ cd lamson_env $ source bin/activate $ pip install lamson
Now let's create a lamson app named ticket-creator that will house the e-mail application.:
$ lamson gen -project ticket-creator $ cd ticket-creator $ ls ticket-creator app config logs muttrc README run tests
Lamson creates files for us to make code organization very easy. Let us next look at the functionality of the files:
$ ls app/ data handlers __init__.py model templates
The app directory holds all the logic for the e-mail application. Right from the models (models), the views (templates) and controllers (handlers), it houses them all! Doesn't this method of organizing the code look similar? Yes, it is an MVC based e-mail app framework!:
$ ls config boot.py __init__.py logging.conf settings.py testing.py test_logging.conf
The boot.py contains the config attributes that is loaded when lamson starts. Most likely, you wouldn't have to touch this file. The settings.py holds all the configuration attributes. This file is analogous to the django settings and is just a plain python file. The testing.py is equivalent to boot.py but is used in test mode. The logging.conf and test_logging.conf hold all the logging related attributes.
The logs directory holds the files where the logging outputs are redirected. To debug your server, this is the place you've to start off. The muttrc file holds the mutt configuration directives to use lamson to send mail and open a local mailbox. The run directory holds the pid and other runtime specific files. The tests directory houses all the test cases you might write while developing your e-mail application.
For this session, let's close with starting the lamson server. In the e-mail app:
$ lamson start $ ls run smtp.pid undeliverable $ ps aux|grep lamson theju 10155 0.2 0.1 21768 7532 ? Sl 19:19 0:00 /home/theju/lamson_env/bin/python /home/theju/lamson_env/bin/lamson start
To see on which port lamson is running, or to modify the port, we can change the port of the receiver_config attribute in the config/settings.py file. To stop lamson, just type:
$ lamson stop Stopping processes with the following PID files: ['./run/smtp.pid'] Attempting to stop lamson at pid 10155
This is the end of the first part where we just dipped our finger nails into this amazing project called Lamson. In the coming post, we are going to see how to write the logic for the application and in the final post on how to deploy this application.
Comments
Reactions
Writing an e-mail application with Lamson - http://bit.ly/hxZhlP - [Hacker News FH]
- Test Driven Development in Python
- Deploying Django apps on Heroku
- Developing android applications from command line
- Deploy Django App in 5 Easy Steps
- Project Management Tools for Start-Ups
- Generating a pdf from an image using PIL and django
- Dynamically attaching SITE_ID to Django Caching
- Screencast: How to deploy Django on Heroku
- Deploying Django apps on Heroku
- How to use pep8.py to write better Django code
- rails
- django
- linkroundup
- django opinion
- opinion
- business
- API
- appengine
- python
- satire
- startup
- Uncategorized
- marketing
- personal
- rambling
- search
- interviews
- seo-interviews
- 5startupideas
- ideas
- seo
- tips
- forms
- paypal
- utilities
- datetime
- web2.0
- Amazon
- algorithms
- presentations
- products
- pinax
- satchmo
- ecommerce
- microsoft
- yahoo
- book
- tutorial
- models
- aggreagtion
- meta
- India
- apps
- about
- CSS
- Design
- wordpress
- test slug
- vim
- urls
- reviews
- javascript
- xmpp
- emacs
- Typography
- Grid Theory
- Color Theory
- iphone
- android
- titanium
- mobile applications
- CSS3
- Browser Compatibility
- mobile
- jobs
- lamson
- django setup
- files
- upload
- jsTree
- hierarchical view
- web page
- Treeview
- coffeescript
- request
- response
- South
- django south
- django migration
- --fake
- screencasts
- django caching
- SITE_ID prefix
- review
- code hosting
- comparison
- unfuddle
- fogbugz
- assembla
- github
- project management
- ticketing system
- gunicorn
- deploy
- nginx
- ubuntu
- vps
- android terminal
- terminal
- programming
- TDD
- Test Driven
- Development
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- October 2011
- September 2011
- July 2011
- June 2011
- April 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- June 2010
- April 2010
- March 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- April 2009
- March 2009
- February 2009
- November 2008
- October 2008
- June 2008
- May 2008
- April 2008
have you tried sentry?