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

5 Answers 5

22

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.

5
  • dynamic DNS is a way to go for people, who don't care if their mail is delivered or not =)
    – lenik
    Jun 28, 2013 at 13:50
  • 1
    Well, it's for people trying to learn how this stuff works anyway :)
    – Kenneth
    Jun 28, 2013 at 18:33
  • I am going to try and get this done during the week and if it works I will check off as answered, no I am not ignoring nor have I forgotten. Jun 30, 2013 at 22:12
  • 1
    2017 update: there is now an official minimal version of Raspbian Jessie. If you install that then there's no need to remove the desktop.
    – JBentley
    May 16, 2017 at 21:30
  • Depends on where you live if the dynamic IP will change often or not. For instance, in Germany, the dynamic IP is switched nightly. A problem I kept running into when I was playing certain games or tried to have connections up for a long period of time. Oct 7, 2021 at 11:29
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 =)

3
  • +1, saved me the time to say pretty much the same thing. I would add, I have been down this route, and ran my own server for about 3 years. I decided to do it because of lost email by my email provider (not my isp). As mentioned some ISPs wont let you play with port 25, check into that. Consider a backup mx as uptime can become an issue for unexpected outages, especially those beyond your control. The worst for me was when I was away for 3 weeks and my router died. Eventually I opted for the gmail solution and haven't looked back. Good luck. And yeah, get a bigger SD card!
    – Madivad
    Aug 23, 2013 at 13:07
  • 6
    @lenik Worst advice ever to use Gmail vs self-hosted, at least from a security standpoint. Also totally not an answer to the OP's question.
    – user10193
    Oct 24, 2013 at 4:46
  • @pilavdzice There is zero evidence that all encryption protocols are compromised. Some people theorize that quantum computers will be able to crack our encryption protocols, but until then, encryption works. Please stop spreading disinformation. As for Google, the leaks about the PRISM program show that Google is a willful participant in dragnet surveillance programs. People with privacy needs should absolutely not trust Google to respect their privacy to the extent that you could trust your life to them.
    – crypdick
    Jul 5, 2017 at 3:54
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!

1
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.

-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

1
  • 1
    Welcome to Raspberry Pi! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Apr 2, 2014 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.