# Best Way to Set up Basic Postfix/Dovecot Stack for IMAP, SMTP, POP3



## Danneskjold (Jul 19, 2012)

Hey Guys,
I've just installed FreeBSD on my (remote) server, and I'm trying to get a simple mail setup going as soon as I can. I have some limited experience with Linux and FreeBSD, but I'm mostly learning as I go.

I found a few guides on how to install application stacks that include Postfix and Dovecot, but they also integrated several other programs that I'm hoping that I don't need.

I'm hoping to: 
1) Receive incoming mail for one - maybe two email addresses that are part of the domain that points to my FreeBSD server.
2)I'd like to be able to download the mail via IMAP, and optionally, POP3.
3)I'd like to send mail via SMTP, with authentication, through the same server.

Can you guys please give me some guidance on which programs I need for this kind of setup, and guide me to the relevant sections of existing tutorials/guides that can walk me through the setup?

Thanks Very Much,
Danneskjold


----------



## vermaden (Jul 24, 2012)

I once created such simple HOWTO:
http://forums.freebsd.org/showthread.php?t=16801

But then I saw that dspam liked to crash one in a while and moved to SpamAssassin.

The dspam recently received some updates, maybe it does no crash now.


----------



## redw0lfx (Jul 24, 2012)

Take a look at this how to from Purple Hat.  I continuously use it for building mail servers, and so far haven't had any issues with the setups.

Although you think you might not need some of the applications, like Maia, SpamAssassin, etc, I would definitely install them anyhow. They don't take up much resources and can be configured pretty easily to prevent a large amount of spam and viruses.


----------



## nx (Jul 25, 2012)

The purplehat howto redw0lfx's linked to works well for me on freebsd9 - no issues so far.

From memory I installed dovecot 1 rather than 2 so that I could follow the instructions to the letter in case the configs have changed in versions.
If you find any errors - check you've modified the configs correctly, and if still having issues, search the purplehat mailing list - most common setup errors are addressed on it.

Lastly, like redw0lfx says, I recommend you install maia and spamassassin etc, at the very least because a lot of the howto is written around maia. Tools like mailman are more optional. If you want graphing in maia, make sure you first google what graphic lib needs to be enabled when installing php. The howto omits the library so no graphs are available in maia if you are following it on a fresh install.

If you want to use opendkim and spf to help your mail be identified as originating from your host.domain and not be filtered as spam, it's easy to add this after following the purplehat setup.

Here's what I used to get spf working:

http://forums.freebsd.org/showpost.php?p=151698&postcount=2

Ignore the dkim-milter commands at the bottom of that link, and use the following link to install opendkim:

http://www.ipsure.com/blog/2012/dkim-milter-is-no-longer-available-how-to-use-opendkim-instead/

This online generator will help you get the formatting right once you have your public key to copy to it:

http://www.dnswatch.info/dkim/create-dns-record

And once you've entered your dkim txt record in your dns, if you are getting dkim errors in your mail headers when testing by emailing a third party eg gmail, this online dkim check will tell you what needs fixing:

http://dkimcore.org/tools/keycheck.html

There's a bit to do but you'll learn a lot and have a really good setup after.

Good luck


----------



## mwatkins (Jul 25, 2012)

Danneskjold said:
			
		

> I'm hoping to:
> 1) Receive incoming mail for _*one - maybe two email addresses*_ that are part of the domain that points to my FreeBSD server.



Given the very small user base, I'd recommend avoiding integrating a SQL database into your solution, for now. Start out using plain text file driven configuration for Postfix, Dovecot, et al. You can always scale up to a database driven solution later.



			
				vermaden said:
			
		

> ... But then I saw that dspam liked to crash one in a while and moved to SpamAssassin.



Some time ago I evaluated dspam for a while on one of my mail servers but had a similar experience with dspam crashing. I ended up replacing it with, if you can believe it, mail/bogofilter. It actually has stood the test of time, which I didn't expect.

Bogofilter doesn't get a lot of action anyway. Some years ago I ran spamassassin on a fairly busy but somewhat underpowered mail system and was looking for a way to reduce the volume of obvious spam hitting it via various postfix and other tweaks. One of the approaches I used was a Postfix policy daemon - for a long time I've been using mail/policyd-weight, and have it tuned / patched to reject a substantial amount of mail before it even hits the postfix queue. This solution still works well for me today, although I'm not sure the project has had any activity for some time now. Still, it is probably worth checking out nonetheless. If you can cut the incoming spam barrage down by a factor of 10 or more, your mail queue (and spamassassin) will thank you.


----------



## vermaden (Jul 25, 2012)

mwatkins said:
			
		

> Some time ago I evaluated dspam for a while on one of my mail servers but had a similar experience with dspam crashing. I ended up replacing it with, if you can believe it, mail/bogofilter. It actually has stood the test of time, which I didn't expect.



I haven't tried it yet (bogofilter), maybe I will when I would need to upgrade that mail box 



			
				mwatkins said:
			
		

> One of the approaches I used was a Postfix policy daemon - for a long time I've been using mail/policyd-weight, and have it tuned / patched to reject a substantial amount of mail before it even hits the postfix queue.



They probably renamed the port to that one:
http://freshports.org/mail/postfix-policyd-weight/



			
				mwatkins said:
			
		

> This solution still works well for me today, although I'm not sure the project has had any activity for some time now.


Last activity on their SF site is from 2010-12-01.


----------

