Sunday, September 21, 2008

Patching Qmail for remote smtp authentication

My ISP (Netvigator) goes to great lengths to block spam mails sending out from its users. All its users cannot connect to SMTP severs outside. This creates a problem for me as I host my own mail server at home.

Normally, when a mail server tries to deliver an email, it will connect to the destination mail server directly. e.g.

Draft an email to on my PC --->
  my mail server --->
  yahoo's mail server

But as mentioned above, my ISP blocks all the access (port 25) to the outside world. So there is no way for my mail server to connect to other mail servers and deliver the emails.

Luckily, by the SMTP standard, I could force the mails route through my ISP's mail server:

Draft an email to on my PC --->
  my mail server --->
  Netvigator's mail server --->
  yahoo's mail server

So far so good. The remaining problem is: the Netvigator's SMTP server requires authentication which my mail server (Qmail) doesn't support! Thanks to open source, it is easy to patch the code though.

  • First, go get the patch
  • Apply the patch to qmail-remote.c
    patch < qmail-remote-auth.patch

    In my case (on FreeBSD), one of the chunks can't be patched. But don't worry, just open the source to patch it manually!!
  • The patched source needs a base64 function (the authentication for SMTP is in base64 format). Go get it here. Unpack the file and copy base64.c and base64.h to the qmail source folder. Compile it.
    gcc -c base64.c
  • Build the new binary
    make qmail-remote

    Replace the existing qmail-remote (usually under /var/qmail/bin) with the patched version
  • Now, the Qmail SMTP routing file (/var/qmail/control/smtproutes) supports username and password. e.g. To route everything from my mail server to Netvigator's SMTP server: username password

1 comment:

get ged online said...

It good to see this information in your post, I was looking the same but there was not any proper resource.. Thanks now I have the link which I was looking for my research…