(Original title: “mail server arrrgh”)
I’m running VMWare Fusion on my Mac. I often run multiple VMs for testing Postgres on various OSes, and decided it would be fun if I could get system emails from the guests on the mac host. Yeah, “it would be fun”. Even though I was working with Postfix, this task gave me flashbacks to my sendmail experiences many years ago.
This is what I had to do to get it working. This isn’t in the order I did all the steps; there was a ton of trial, error, and wtfery that went on here. Also, this is on a machine that’s behind a few firewalls; probably not something you want to configure on a server that actually has a port open on the Internet. Although it seems that most of the mailserver-related footguns are no longer enabled by default. Caveat Emptor, or something.
Host: Mac OSX Lion 10.7.5
Guests: CentOS 6.4
VMWare: Fusion 4.1.3
Set up postfix on the mac host; starting with the instructions here: http://www.phase2technology.com/blog/how-to-enable-local-smtp-server-postfix-on-os-x-leopard/
This “worked” in that the simple “telnet to port 25” test worked (see “Useful tools and commands” below), but I had to make some additional changes to receive mail from my guest OSes.
On the Mac host, I made some changes to /etc/postfix/main.cf:
myhostname = princess
mydomain = localdomain
mydestination = $myhostname, $myhostname.$mydomain, localhost.$mydomain, localhost, mailhost.$mydomain
inet_interfaces = 192.168.247.1, 127.0.0.1
mynetworks = 192.168.247.0/24, 127.0.0.0/8
The value for inet_interfaces is the IP of my vmware interface, obtained from ifconfig. You want the vmware8 interface and it should be a 192.168 address. I just added the whole vmware subnet to mynetworks parameter. You can read more about these parameters in main.cf; it is surprisingly well-commented.
I also commented out imap_submit_cred_file line as discussed here https://discussions.apple.com/thread/3247974. I’m not going to bother with this for local use.
‘postfix reload’ did not apply these changes for me; I had to explicitly stop and restart it1:
On the guest:
First, I added the vmware host IP to /etc/hosts:
192.168.247.1 princess princess.localdomain mailhost mailhost.localdomain
This worked via the ‘telnet to port 25’ test method, but regular email wasn’t getting delivered; in fact, it was bouncing. Looking into the mail queue, I discovered it was trying to use a completely different IP for its mailhost.
I checked out the ‘hosts’ value in /etc/nsswitch.conf (just grep hosts /etc/nsswitch.conf) and determined that it was set to ‘files dns’, which ordinarily indicates that /etc/hosts should override dns from the vmware dns server. That wasn’t what was happening. A bit of investigation revealed that postfix was already running2, so I had to dink with it on the guests as well.
Fixed by editing /etc/postfix/main.cf (on the guest) to include this:
relayhost = mailhost.localdomain
Thanks to mjm for keeping me sane during this.
‘postfix status’ # see what postfix thinks it’s doing and get its pid, since the processes aren’t named postfix and therefor ‘ps -ef | grep post’ won’t show them :)
netstat -an | grep ‘\.25 ‘ # see if anything’s listening on port 25:
(master *) :::-->netstat -an | grep '\.25 '
tcp4 0 0 192.168.247.1.25 *.* LISTEN
tcp4 0 0 127.0.0.1.25 *.* LISTEN
mailq # see status of queued mail messages
[tail|vi|whatever] /var/log/mail.log # see connections, postfix startup/reload, etc
SMTP test program, something like this http://www.port25.com/how-to-check-an-smtp-connection-with-a-manual-telnet-session-2
You may want this as well: http://topicdesk.com/faqs/os-x-server-mail-services-faq/69-how-do-i-completely-disable-postfix-and-cyrus
1 – I’ve since been told it’s better to use launchctl to control processes.
2 – This surprised me, given the other things that are locked down/not available on the CentOS default.