Archive for February, 2012

Sending email via HTTP POST

A number of services have popped up lately for sending email from your web app via HTTP. Web developers know HTTP, and so enjoy the fact that they can send email this way. But they all cost money. What if you could do it yourself, for free?

So I created a Haraka plugin using Express which provides a REST API for sending emails using HTTP POST parameters to fill out the template.

It’s very simple, and could easily be extended. I’m using it from EC2 (with an Elastic IP – don’t use their normal dynamic IPs for this).

Here’s the code: https://gist.github.com/1924944. Templates should include email headers and are stored in config/mail_template, then you just POST to http://localhost:5000/SendEmail/example (if your template file is called “example”) with sender and recipient parameters encoded in the body of the request.

There’s no fancy statistics like there are for sendgrid and other such services, but you have full control and writing more plugins is as easy as pie!

February 27, 2012 at 8:34 pm 6 comments

ANNOUNCE: Haraka v1.2.0

I’m sure most of you will have heard the good news already – Haraka is now live in production at craigslist. Just telnet to their MX servers on port 25 and see our banner!

 
I’ve just pushed 1.2.0 to NPM. Changes are:
 
  • Improved logging again
  • Added a reseed_rng plugin necessary for running under cluster on 0.4.x
  • Added an attachment blocking plugin (block by filename or content type)
  • Updated dns plugins to use new dns_list_base base class which provides stats (in redis) and more functionality
  • Removed recursion from clamd and smtp_forward plugins to prevent stack blowing on large mails
  • Mail loops are now prevented by default
  • New daemonize plugin which sends Haraka into the background
  • Advanced new RCPT and MAIL parameter blocking plugins (rcpt_to.access and mail_from.access)
  • Added unit testing code
  • Wrote a tutorial for setting up Haraka as an outbound mail server
  • Added an alias plugin (for rewriting rcpt to addresses)
  • The usual slew of bug fixes and misc small improvements
 
Haraka v1.2.0 is available on npm, and installed via “npm -g install Haraka”.

February 27, 2012 at 7:12 pm Leave a comment

Setting up Haraka for outbound email

I just wrote a tutorial for this, because it’s incredibly easy and people were getting bogged down in too many details :)

Click here for the tutorial.

February 23, 2012 at 4:47 pm Leave a comment

craigslist deploys Haraka

craigslist deploys Haraka SMTP Server

craigslist has implemented Haraka SMTP Server, based on its compelling combination of scalability and configurability.

craigslist classifieds are used by over 50 million users each month in the US alone, generating massive demand for its email relay services – demand that Haraka is designed to accomodate with ease.

Haraka plugins written in Javascript can access any part of the SMTP conversation, for email filtering, sender and recipient filtering and modification, authentication, content modification, and custom delivery. By leveraging the Node.js framework, the Haraka project provides extremely high mail server performance along with ease of use and flexibility.

craigslist has contributed significantly to Haraka development, and hopes to continue providing new plugins and features to the open source project.

Haraka can be found here: http://haraka.github.com/

February 17, 2012 at 3:24 pm 4 comments

Github Continuous Deployment to EC2

After searching far and wide for EASY solutions for continuous deployment to EC2 from our Github repository I decided to write my own, and detail it here so that other people could find it easily on google.

Here are the tools I use for this:

  • EC2 running Linux (Ubuntu)
  • Ruby and sinatra (but you can use something else if it floats your boat)
  • Nginx frontend
  • runit for keeping services running, and logging

I’m not going to go into details on how to setup EC2 – just get a Linux host of some sort (we’re using Ubuntu) up and running there, and assign an easy to remember CNAME to point to it (below I call this “yournewhostname.yourdomain.com”).

Firstly create a user account for your deployment on your EC2 instance, and create ssh keys for this user – we’ll call this user “deployment”. Then create a github account for that user, and add your ssh public key into that new account’s github configuration. [This is necessary only for private repositories - if you're using a public repo then it's not required]. You then need to make a “Team” for this user, so that account can get “pull” request rights on your project. We call our team “EC2 Deployment”. Set the team up so it gets pull rights only. Add this new user to that team.

Then in your Github repository, go into Admin, Teams, and add the “EC2 Deployment” team to your project. Now while you’re in Admin, go into Service Hooks, and add a Post-Receive URL hook pointing to http://yournewhostname.yourdomain.com/.

Now configure nginx to forward requests to yournewhostname.yourdomain.com to a server on localhost on a unique port. I use 10001, but pick whatever works.

Now you need a Ruby sinatra app running on 10001 which receives the POST data, performs a pull request, and restarts the service. This has to run as root (to restart the service) so make sure you audit this code!

Finally, here’s the sinatra code that processes the request:

post '/' do
 if (!params[:payload])
   return "Stop sending me rubbish"
 end
 push = JSON.parse(params[:payload]);

 if (push['ref'] != 'refs/heads/master')
   return "Not a push on master - ignorning"
 end

 repo = push['repository']['name'];
 
 Dir.chdir("/var/deployments/" + repo)
 if (system("/bin/su", "deployment", "-c", "/usr/bin/git pull"))
   puts "git pull of #{repo} successful"
   if (system("/usr/bin/sv", "kill", "."))
    return "Restarted!"
   end
 end
 return "Thanks";
end

I removed a lot of the logging here, but you get the idea. It’s pretty simple, and doesn’t do any testing or anything like that, but I’ve provided this here for you as an example, not as the final solution.

PS: We’re hiring. Come work for us!

February 9, 2012 at 6:12 pm 2 comments



Follow

Get every new post delivered to your Inbox.

Join 161 other followers