Setting up a Mail Server with Homebrew


#1

Greetings!
Now that MacOS server is essentially dead, I’m setting up my newest server using Homebrew for pretty much everything. I’ve got MariaDB for the database, PHP7, apache, it all works great.

I’ve worked with all this software before at various levels, from easy GUI config (Snow Leopard Server) to manually compiling php and editing httpd.conf on old 10.1 machines way back when.

But I’ve only ever done the mail server through OS X Server. Now I have to do it all through Homebrew. I’m wondering if anyone knows of any good beginner guides to setting up mail servers this way?

I need SMTP and IMAP. I need a way to set up my users. I don’t need to migrate in any mail, I can do that just as easily from the client side as I have full access to all accounts. I don’t need anything extra fancy, I Just need something that can be configured and maintained with a reasonable amount of work.


(Sean Molenaar) #2

hardly anything you can install with homebrew in that stack is macOS specific. I’d recommend looking for linux guides.


#3

This is too related for me to start another post. But I’m looking through brew and I see Dovecot, but I’m not seeing Postfix. Only Sendmail. What is up with that? Do I have to tap something separate to install Postfix? Or does it have a different name or something like that?


(Sean Molenaar) #4

If something isn’t in homebrew it’s probably because it was removed or never submitted. You can search for postfix on github to see if there’s any trace of it.


(John) #5

Isn’t postfix installed by default? Mine’s at /usr/sbin/postfix.


#6

Well sure, like many pieces of software. But it’s going to get updated and changed based on apple’s software updates. I’d rather use a separate version installed by brew that i am in control of.


(John) #7

Fine, but you said that you had to do it through homebrew. You don’t.


#8

Also the installed version of postfix is old and not compatible with the admin app I was hoping to use (postfix admin).


(Sean Molenaar) #9

You can suggest new software to homebrew, it’s just not there yet.


#10

I’m running Postfix+Dovecot+MySql on my Mac Mini. SSL, LetsEncrypt, Apache etc on Mojave. It’s been working fine for ages now. I had to download and build Postfix and Dovecot myself to get the right switches in it, but that’s pretty easy. So long as you have the XCode Command Line tools installed to do the builds and Perl. Again, not Apple’s Perl which is useless. But ‘brew install Perl’ - but… I’m still trying to discover how to install Mail:: Spamassassin into the mix now. I had it in MacPorts, but I’m removing that in favor of Homebrew - which doesn’t have it. :frowning:
But in short - it’s a long and frustrating process, but once you get it it works well.


#11

Hows it been working for ages if the software just came out the other day?


(James Brown) #12

Do you have any notes on how you did this? I’ve been doing the same thing myself, and have got stumped with Postfix. It won’t run but I can’t find anything in the logs.

Any info you have would be most appreciated.


#13

What software just came out the other day? Postfix has been around for years.


#14

Hi, first of all, to check some things. OSX comes with a version of Postfix built in. Are you trying to get it all running with the OSX version, or have you “homebrewed” in a new version?
If you are trying to use your homebrew version, you have to disable the OSX version first.
That means redirecting your plist startup file to your version, and not the OSX version for a start.
Stop the running version, which will be the mac version.
sudo launchctl unload -w /Library/LaunchDaemons/org.postfix.master.plist
Then check the PATH statement. Then try running your own version of Postfix from the command line, including telling it where your new config file is.

Stop me if you already know and have done this. Because from this point on it gets a little more complex.
I actually compiled all of my binaries by hand - not using homebrew - so I could put them and their packages into my own directories. /usr/local/etc/postfix and so on. Also because I have a lot of things being used by Postfix that are not in the buuilds either osx or brew. Because, every time you do an update of the mac os, it overwrites your lovely working Postfix.
It also overwrites the plist file too - but after an update now I only have to modify the plist file, not all the rest. It drives me nuts but what do you do?

Ok, I’ll wait till I hear from you. It really depends on how complex you want your Postfix mail system to be. If you are just using a local network thing and a bit of internet traffic, the built in one will porbably work. If you replace it with the brew one, that too can be modified at build to get a lot of the things you need, but I don’t know how to do that. I was told, but it still didn’t do what I wanted. So I compiled my own from binaries. After a LOT of trickery, because as it happens, one of the libraries I needed to use only came with MacPorts. So I’ve ended up with a bit of a mishmash. But, it works,
Let me know just what you need and I’ll see if I can help further.

oh by the way. Watch /var/log/mail.log and /var/log/system.log in Terminal windows.


#15

Ok, sorry, I just saw this.
“I need SMTP and IMAP. I need a way to set up my users. I don’t need to migrate in any mail, I can do that just as easily from the client side as I have full access to all accounts. I don’t need anything extra fancy, I Just need something that can be configured and maintained with a reasonable amount of work.”

Ok, so your brew will work. and probably the built in Postfix. I’ll find my notes and geet back to you.
But essentially, if you want to use brew versions, then you have to stop the built in one first.
I realize it’s not a server you have there, but it does come with Postfix.


(James Brown) #16

Thanks for you quick reply. Have installed Dovecot and mySQL via Homebrew. Installed Postfix manually (ie complied from source.

Using:
$ sudo postfix stop
$sudo postfix start
postfix: Postfix is running with backwards-compatible default settings
postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details
postfix: To disable backwards compatibility use “postconf compatibility_level=2” and “postfix reload”
postfix/postfix-script: starting the Postfix mail system
postfix/postfix-script: fatal: mail system startup failed

to start Postfix.

There was no /var/log/mail.log, so I had to create it:

$ sudo touch /var/log/mail.log

$ sudo chmod 777 /var/log/mail.log

but it is empty.


(James Brown) #17

If I try to start Postfix with

sudo /usr/local/libexec/postfix/master master I see this in the Console:

default 18:39:45.495912 +1100 sudo Too many groups requested (65). Can cause performance issues when network directories are involved
default 18:39:45.510141 +1100 sudo Too many groups requested (2147483647). Can cause performance issues when network directories are involved
default 18:39:45.522268 +1100 sudo jlbrown : TTY=ttys012 ; PWD=/Users/jlbrown ; USER=root ; COMMAND=/usr/local/libexec/postfix/master master
default 18:39:45.530138 +1100 taskgated MacOS error: -67062
default 18:39:45.537694 +1100 master fatal: usage: /usr/local/libexec/postfix/master [-c config_dir] [-D (debug)] [-d (don’t detach from terminal)] [-e exit_time] [-t (test)] [-v] [-w (wait for initialization)]

(James Brown) #18

This seems to work better:

$ sudo /usr/local/libexec/postfix/master -c /usr/local/etc/postfix/

Still nothing in /var/log/mail.log though.


#19

excellent.

Logs are turned on in main.cf

smtpd_tls_loglevel = 2
smtp_tls_loglevel = 1

the log file could be maillog, or something similar. But it will be in /var/log

From my notes

smtpd_tls_security_level = may

smtp_tls_security_level = may

smtp_tls_loglevel = 1

smtpd_tls_loglevel = 1

Smtpd means mails you receive from outside, smtp covers mails you send to other servers.

Both settings can have three different values: none, may, encrypt. The may-option is recommended because it doesn’t lock out servers who don’t support encryption.

The two last options enable logging of encrypted connections. This is useful to verify the cipher strength and if everything is working properly.


#20

Trouble is, that wont keep running. Next reboot - it’s gone, and the plist file will be trying to start up again.
You will need to edit the plist file and tell it where your config files are, unless you did that when you compiled Postfix. Which is what I did. I compiled in the default directories for it - mostly /usr/local/etc and so on. So I don’t need them in the plist file.
Apart from in the plist file, it has /usr/local/libexec … which I put in. The native one is different and will overwrite yours. and when you reboot, it will try and run the old postfix.

Are you also watching /var/log/system.log to see what happens when you reload postfix?