18

I just got my Pi today, and of course I can't even use it because I got the wrong HDMI to DVI converter but that's besides the point and question.

My question is the following:

I have decided to ditch Gmail and to setup my own email server. First I know I will buy a domain name, I then want to use my Pi to send and receive email in place of Gmail.

Do I have to install a web-server first? How should I go about this. What is the best way to go about it? I will be setting up two email addresses for this account and we should both be able to log into our respective emails simultaneously.

I have the Model B pi with a 4GB card with an OS preloaded from Canakit.

There is a similarly related post here but this person is beyond where I already am.

Pi Email Server

MCP_infiltrator
  • 283
  • 1
  • 5
  • 9

5 Answers5

21

I have set up my pi for use as a web and mail server and it works just fine. So far I have been running from a standard 4GB SD card (with a few modifications described below) and it has had an uptime so far of a little over three months.

It is not hard and there are many tutorials out there for setting these things up. Incidentally, I used most of the Ubuntu tutorials for setting up mail related items (postfix, dovecot, etc.). You should realize that there are very few differences between setting up a server on a raspberry pi and other machines so general Debian/Ubuntu guides should mostly apply to raspbian.

That being said there are a number of issues with the pi itself that you should address.

  • Extend the lifespan of your SD card as described in this post. I would say the more suggestions you take the better.
  • Remove the default user (pi).
  • Remove the graphical desktop as described in this post.
  • Use the pi setup tool to minimize the amount of RAM used by the graphics processor (Hint: If you just set up ssh it does not need any).

A few general server notes:

  • Set up your ports on the router (25 for mail, 22 for ssh, 80 for web and or the related ports for imap and pop3).
  • Setup the pi with a static IP address on the local network so the router has something to forward traffic to.
  • Use fail2ban or similar blacklisting tool. There are a lot of script kiddies out there.

With the server itself I used the Ubuntu community wiki to set up postfix with greylisting and dovecot. I would not bother with CLAM as it uses a lot of resources and simple greylisting removes something like 90% of spam mail anyway.

Another point is that if you don't care about the server being available 99.9% of the time you don't need to pay for a static IP. As long as the server is connected on a dynamic IP from you ISP it is not likely to change unless you unplug your router for a longer period of time. I have been having the same dynamically allocated IP for as long as the pi has been connected to the internet. And should it change it is a simple update of my DNS manangers website and a few hours later it is back online.

For webmail you will need a webserver. I would recommend nginx with roundcube. Plus side for using a webbased client is that you only need to open port 80 as all communication with between the mail server and client happens on the local machine.

Kenneth
  • 721
  • 1
  • 4
  • 11
5

I would not recommend to do this. Unattended e-mail server very quickly becomes a spam machine, and proper taking care of it very quickly becomes a full-time job.

To get a working e-mail server you'll need to acquire a domain name, set up DNS records for your mail exchanger, set up reverse DNS pointers (most internet providers will NOT do that and will NOT allow that), harden your installation against hacking attempts, set up your favourite mail software, set up your favourite spam filter, set up your router to allow inbound/outbound connections on the port 25 (most internet providers will NOT allow you to do that), configure everything and make sure it's connected to the internet and running 24/7.

The most important part is reverse DNS and outbound port 25, and unless you've got a VERY friendly internet provider, you will not get it working.

So, unless you have a very good reason, stick with google. Google does a very good job (i am totally unaffiliated and don't have stocks =)

lenik
  • 11,533
  • 2
  • 32
  • 37
3

First this first: Will your home network support it? You will need a static public IP address and the ability to setup a port forward (port 25) going to your Pi. Your connection will also need to be always up (not dialup, probably not an issue, but worth mentioning.) You will probably have to pay your service provider for the static address.

From there, yes you will need to setup an email server to run on the pi. You will probably want a web interface as well. I have used this tutorial in the past with success. Look at SquirrelMail for your interface. Your Pi will need to be running 24/7/365 for this to be a viable option. I would start with a bigger SD card (32gb?), burn a copy of raspberian on it and proceed from there.

Keep in mind before you start this process that you will also want to address spam filtering, and ensure that you do not setup your SMTP server as an open relay, or people will use it to spam everyone else.

Setting up an email server is not a small endeavor, and probably not worth it for a single mailbox. You can probably pay for a single mailbox on your own domain name on someone else's servers for less than the cost of a static IP address from your service provider, have better uptime, better spam filtering, support, and be able to use your pi for something else.

In light of all this, if you choose to embark on this quest, good luck!

Butters
  • 1,597
  • 8
  • 23
1

One major roadblock is that many ISPs annoyingly do not allow outbound port 25. I wasted hours "debugging" my home mail service, only to discover this in the end. If your ISP blocks it, the best thing you can get is a receive-only mailbox.

Not saying that you shouldn't do it (since you shouldn't trust Google). Just add that to your list of things to check since the accepted answer didn't mention this.

Also, no real need for a static public IP address, though you need a static private IP for the Pi of course. My non-static IP hasn't changed by itself except for that time we had a bad power outage.

sudo
  • 111
  • 3
-2

If you are using ISP DHCP then you might be listed on the spam list you need a static ip or paid Static ip vpn

james
  • 1