I run cron jobs on my Mac laptop, and so I want the mail daemon to be able to send the output mail to my regular mail account. I've got that working (my local account has a .forward file), but I'm often on networks where connecting to the destination's MX on port 25 doesn't succeed.

Therefore, I would like to have the local mail daemon send its outgoing mail, regardless of the destination, to another SMTP server (which happens to be a SSH port-forward to a server under my control). How do I configure the Apple-supplied Postfix to do this?


I tried setting relayhost = [localhost]:40125 (where 40125 is the SSH port forward), but while I can now send mail to a proper Internet mail address (e.g. kpreid@switchb.org), cron job mail (which is addressed to kpreid@<whatever the DHCP hostname is>) doesn't get delivered. From the one bounce I saw, it appears that this causes all mail, even for the local hostname, to go to the relayhost first.

Therefore, I need a way to relay to [localhost]:40125 unless the address domain is this machine's domain (which varies frequently).


You need to set the relayhost directive in /etc/postfix/main.cf (and maybe tweak some other settings, but that's hard to say without knowing the default config from Apple).

  • It worked; no additional configuration was needed. I added relayhost = [localhost]:40125, where 40125 is the SSH port forward (-L localhost:40125:localhost:25); according to the comments in the file, the square brackets specify to connect directly rather than looking up a MX for the domain (which might be unnecessary for localhost, but hey). – Kevin Reid Aug 22 '10 at 12:46
  • Unfortunately, while this works for general outgoing mail, this seems to cause cron-job mail to fail because it's trying to send to "<account>@<whatever my DHCP-generated hostname is>" via the relayhost (at least, I received one bounce for this), rather than first finding the .forward in the local account. Any suggestions? – Kevin Reid Aug 28 '10 at 21:19
  • I suppose the mydestination setting isn't correct then, or maybe one of the other my* settings. You can find an explanation of all available settings in man 5 postconf. Also, on Ubuntu (I'm not sure if Mac OS X uses "Vixie cron" too?) it's possible to tell cron who to mail by setting a MAILTO environment variable in crontab (see man 5 crontab). – JanC Aug 29 '10 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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