Find file
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (33 sloc) 3.89 KB

CouchDB Plugin for Haraka

Caution: this is very beta

This is a plugin for the excellent node.js Haraka email server that will receive incoming email, parse and store them as JSON in CouchDB. For a mail client to use with this check out CouchMail

Ubuntu installation:

Here's how to set up your own SMTP server from scratch!

Install git (sudo apt-get install git-core)

Install node.js via these instructions. It is recommended that you build node yourself as opposed to using a package manager because it will make it easier to upgrade later. This app was developed against node version 0.4.8. You can install a specific version by running git checkout v0.4.8 before running configure/make/make install.

Install npm, the node package manager: curl | sh

Download CouchBase server community edition. This is a prebuilt binary of CouchDB v1.0.2 with the GeoCouch plugin installed. There are other ways to install CouchDB on Ubuntu but they are a pain. Any Couch greater than v1.0 will work. To install:

# make the installation package executable
chmod +x couchbase-server-community_x86_64_1.1.deb
# install couch
dpkg -i couchbase-server-community_x86_64_1.1.deb

By default CouchDB is not accessible to external network traffic, so you will have to be logged into the machine running Couch to interact with it. You can open up Couch to external traffic by setting the bind_address to in the Couch configuration:

curl -X PUT http://localhost:5984/_config/httpd/bind_address -d '""' -H "Content-type:application/json"

However, before you do this please be sure to read about the CouchDB security model.

Install Haraka: npm install -g Haraka

The default Haraka configuration assumes you have a couch running at http://localhost:5984 (this is also Couch's default). You can change this setting in the file config/couchdb.url. Be sure to include your admin username and password in the URL if you have one set.

Also make sure to edit the file config/me to contain the domain name that you want to receive mail at (the same domain as your MX record, or localhost for dev testing)

You can also set the database prefix name in the file config/couchdb.dbPrefix. The default value is "mail_", which means that messages sent to will be stored in a database called mail_bill in Couch.

git clone git://
cd haraka-couchdb
npm install request
npm install buffers
sudo haraka -c .

Note: sudo is usually required to bind to port 25

You are now running a mail server! If you want to receive real mail using Haraka, you simply need to install this on a publicly accessible server and set your domain's MX DNS record to point at that server. For example, if you have an Amazon server with the address and you own the domain name, just add two DNS records to a CNAME record pointing at and an MX record pointing at

Test it out

If you have an MX record set up correctly, just send an email to A database called mail_anyone will be created in your Couch and your message will be stored in it as JSON.

If you just want to test it locally, you can execute the included test_send.rb ruby script to send a test email to yourself:

gem install mail mustache
ruby test_send.rb

In your Couch you should now see a database called mail_pizza (since the test messages are sent to a user called pizza) with some messages inside.