No description, website, or topics provided.
Ruby
Permalink
Failed to load latest commit information.
app
config
db
lib
spec
.gitignore
.slugignore
Gemfile
Gemfile.lock
Procfile
README.md
Rakefile
config.ru

README.md

mailtub

Access your email via a RESTful web API.

Installation

Setup haraka server to receive mail

Begn by create a droplet on digital ocean. Name it mail and make it 512 RAM. I choose San Francisco because that is nearest me. Make it Ubuntu 12.04 x64.

Cool, now ssh in.

ssh root@DROPLET_IP_ADDRESS

Install vim

apt-get remove vim-tiny
apt-get install vim

Install git

apt-get install git-core

Set the root user's password.

passwd

Restart ssh after that.

service ssh restart

Add a user.

adduser yourusername

Give the user privileges.

visudo

Add the following.

root    ALL=(ALL:ALL) ALL
yourusername ALL=(ALL:ALL) ALL

Next to be extra safe let's change the ssh rules.

vim /etc/ssh/sshd_config

Set or add the following settings in that sshd_config file.

...
Port 25999
PermitRootLogin no
AllowUsers yourusername
...

Restart ssh.

service ssh restart

Ok, logout and login as the yourusername user.

ssh yourusername@IPADDRESS

Install oh-my-zsh

sudo apt-get update && sudo apt-get install zsh
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
chsh -s /bin/zsh

Install vundle.

git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

Set your ~/.vimrc to look like the following.

https://github.com/scottmotte/dotfiles/blob/master/vimrc

Launch vim and run :BundleInstall.

Now, install redis.

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install tcl8.5

Download redis (latest at writing was 2.6.16).

wget http://download.redis.io/releases/redis-2.6.16.tar.gz
tar xzf redis-2.6.16.tar.gz
cd redis-2.6.16
make
make test
sudo make install
cd utils
sudo ./install_server.sh

Now start and stop it as you need.

sudo service redis_6379 start
sudo service redis_6379 stop

Now we can setup haraka.

Install nodejs.

sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Then setup haraka.

sudo npm install -g Haraka
sudo haraka -i /etc/haraka

Comment out all the plugins in /etc/haraka/config/plugins.

sudo vim /etc/haraka/config/plugins

Add data.redis to the end of /etc/haraka/config/plugins.

data.redis

Setup the haraka-redis js plugin.

cd /etc/haraka/plugins
sudo npm install -g redis
sudo npm install -g microtime
sudo npm install -g redis-wstream
sudo wget https://raw.github.com/scottmotte/haraka-redis/master/data.redis.js
cd ..
sudo haraka -c .

Edit haraka to daemonize by default.

sudo vim /etc/haraka/config/smtp.ini

Uncomment the daemonize=true line as well as the log and pid file locations.

Start the haraka service

sudo haraka -c /etc/haraka

Click here for more detailed haraka install instructions.

All done, now you have a mail server accepting mail and dumping it into a redis database.

Exit your server and let it run.

Deploy mailtub to heroku

Before you do the following, you will need an account on heroku and have already installed the heroku toolbelt.

git clone https://github.com/scottmotte/mailtub.git
cd mailtub
heroku create
git push heroku master
heroku run rake db:migrate
heroku config:set REDIS_URL=redis://ipaddress_of_above_mail_server:6379
heroku addons:add scheduler:standard

In the scheduler add the following to run every 10 minutes.

bundle exec rake sync

API

GET /

GET /sync.json

GET /raw_emails/index.json

GET /emails/index.json