lostwebsite.net/ posts/ debian/ receiving mail directly

This is for the record. As I write this entry, I no longer use this technique.

For no particular reason, I've always wanted to receive emails directly on my computer through SMTP. For readers not familiar with how SMTP works, let's just say that SMTP is a postman able to deliver your emails to the post-office, but that is also able to deliver emails directly to your door.

People have got used to get their emails through a Post-Officile Protocol (POP3). You can also use IMAP for the same purpose but it doesn't really fit my metaphor so I will not talk about it. The SMTP postman can also knock to your door (port 25) and deposit the mail right at your computer if you let the rest of the Internet know you want to receive your mail that way (through MX records).

Using a cheap ISP with a dynamic IP address is like changing the door address every so often. Nobody out in the Internet really knows where you live at any point. You can mitigate that by using an handy dynamic DNS service, which I do, but it's not like having a permanent home with a domain that everyone knows about.

Also, Sympatico, my ISP, blocks port 25. That means nobody will every be able to knock at my door. I can't let the whole Internet know that I should receive mail at port 10025 for example.

There are some service that can receive mail for you then route it to the correct port. The prices vary with the features provided by the service. I have not seriously considered paying for something that I can find no practical advantages to.

Nonetheless, I still wanted to receive mail from the Internet directly on my small network, without needing to switch to another ISP.

I successfully received mails from the wide Internet yesterday.

What you need is:

The provider

I use HCOOP. It it my Hosting Provider, and Email Provider, and Pretty-Much-Everything Provider. It's quite cheap and very flexible. It doesn't have any big uptime guarantees and expects a below average knownledge of Apache and DNS configuration but I can deal with that. In fact, I love to deal with that.

So the provider was not a problem for me. Other hosting solutions might not provide you with the possibility of using procmail at all.

The SMTP server

I use Postfix on the receiving computer. It defaults to port 25 of course. All I needed to do in order to make use another port was to edit the /etc/postfix/master.cf file, find the line describing the SMTP service, and change the service the port number you want Postfix to listen on for SMTP requests.

The dumb SMTP server

Some places call that a nullmailer. This is a SMTP client that is just meant to send a mail to an SMTP host.

My provider already had ssmtp installed. I also looked at esmtp for inspirations. There are probably several variants of such software out in the Internet.

The procmail hack

I did not find this verbatim on Internet, but I'm pretty sure you can find several variants of that through Google.

:0wc
| formail -k -X "From:" -X "Subject:" -X "To:" -n 3 -s \
      /usr/sbin/ssmtp -Cssmtp.conf your@email.com

This rule basically tell procmail to send all mail through a pipe starting with the formail program. formail is used to format a mail message before further processing. The switch I pass it tells it to remove all headers but From and Subject from the mail before calling ssmtp. ssmtp.conf is the configuration file for ssmtp. I won't paste it here since it's quite trivial and anybody interested in using it will figure out what to write there from the manual page.

This is probably not an exhaustive shopping list of how I got it done, but without those basic blocks, you wont get it done.

Once I got that working. An avanlanche of problems and potential problems made me realize that this was way much troubles that it was worth.

In short, such acrobatics with emails was too much trouble for me. It doesn't mean I could not have made it work, but that the energy needed to make it work correctly was too much for the value of the end-result I was after. I write this entry as a statement to say that I will spend time trying working on this again, unless I find a reason better than "It'd be cool!".