Enabling postfix for outbound relay via Gmail on OS X Lion

14 02 2012

The background

Mac OSX comes with the postfix MTA, which is a fully featured SMTP server. Under normal circumstances, there is usually no need to enable or configure this software, as most email access is usually done via GUI clients such as the Mail.app – which uses the POP/IMAP and SMTP settings to connect with the email service provider.

However, there are certain circumstances in which having a local SMTP server is very useful, such as:

  1. Allowing the batch logs and output from the cron daemon or other scripts to be sent via Internet email (this is otherwise delivered locally)
  2. Testing email based code; which requires a local sendmail like SMTP server to be present

For such use cases, the postfix server is ideal, as it provides all the features needed (and much more), and is also a nice drop-in replacement for the sendmail program.

While postfix can be used as a full-fledged SMTP server that connects directly to the mail-servers on the Internet, for the use cases above, it is usually better to redirect (i.e., relay) the emails via an authenticated and known server (such as Gmail), as this helps avoid a lot of constraints around open-relays, which are mostly blocked these days to prevent email spam.

Note that configuration of postfix does require dropping down to the command-line, and fiddling with system files. While not complicated, it is definitely not for faint of the heart (though much easier than configuring sendmail).

What you need to know (pre-requisites)

Some of the basic pre-requisites are:

  1. Understanding of the shell prompt and the Terminal.app program
  2. Usage of the sudo program (all the configuration files are owned by root, and hence usage of sudo is essential)
  3. Usage of any command line editor such as vim, Emacs, nano, or any other editor of your choice, that can be invoked with super-user rights (usually via sudo)
  4. A basic understanding of the Apple launchd service manager
  5. The configuration files
  6. A Gmail email ID (actually, any SMTP server credentials will do)

While this article will go step-by-step with the configuration process, knowledge of the above will allow a deeper understanding of the “why” for the changes done.

In the steps below. the $ character before any command represents the shell prompt. Also, I will assume usage of the vim editor in the steps below.

The configuration Files

The configuration files that will be changed are:

 
Name Location Purpose
org.postfix.master.plist /System/Library/LaunchDaemons launchd Configuration for postfix
main.cf /etc/postfix The main postfix configuration
aliases /etc/postfix Local recipient aliases
generic /etc/postfix Sender aliases (for external mail)
passwd /etc/postfix/sasl Relay host authentication

Note that the “/etc/postfix/sasl” directory might not exist, in which case, we will need to create it from the shell prompt:

$ sudo mkdir /etc/postfix/sasl

Step 1: Update the launchd configuration

The org.postfix.master.plist file located at /System/Library/LaunchDaemons/ is used to start or stop the postfix program on demand, as and when any email is submitted to the mail system for processing. The basic Apple setup is fine, but may need a little tweaking (in my case, the file had a couple of tags which prevented postfix from being started.)

We need to edit the file (as a super user) to match the following content:

$ sudo vim /System/Library/LaunchDaemons/org.postfix.master.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>org.postfix.master</string>
        <key>Program</key>
        <string>/usr/libexec/postfix/master</string>
        <key>ProgramArguments</key>
        <array>
                <string>master</string>
                <string>-e</string>
                <string>60</string>
        </array>
        <key>QueueDirectories</key>
        <array>
                <string>/var/spool/postfix/maildrop</string>
        </array>
        <key>AbandonProcessGroup</key>
        <true/>
        <key>OnDemand</key>
        <true/>
</dict>
</plist>

Step 2: Edit the /etc/postfix/main.cf file

The next step is to edit the main configuration file for postfix. Do make a backup of the current file before editing.

$ cd /etc/postfix
$ sudo cp main.cf main.cf.orig
$ sudo vim main.cf

Note that the main.cf file is a pretty large one, and has a lot of commented out sections, which should be left as is. Please add the following lines at end of the file.

# Set the relayhost to the Gmail Server.  Replace with your SMTP server as needed
relayhost = [smtp.gmail.com]:587
# Postfix 2.2 uses the generic(5) address mapping to replace local fantasy email
# addresses by valid Internet addresses. This mapping happens ONLY when mail
# leaves the machine; not when you send mail between users on the same machine.
smtp_generic_maps = hash:/etc/postfix/generic

# These settings (along with the relayhost setting above) will make
# postfix relay all outbound non-local email via Gmail using an
# authenticated TLS/SASL session.
smtp_tls_loglevel=1
smtp_tls_security_level=encrypt
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl/passwd
smtp_sasl_security_options = noanonymous

Step 3: Edit the /etc/postfix/aliases file

We need to make a minor edit here, to allow mails sent to the root ID to your local user mailbox.

$ cd /etc/postfix
$ whoami                # This will provide your local user name
$ sudo cp aliases aliases.orig
$ sudo vim aliases
$ sudo newaliases

Find the line in the file which is:

#root:              you

and replace the “you” with the username provided by the whoami command above.  Also, remove the “#” from beginning of the line.

Remember to run the newaliases command (the last command above), or else changes will not take effect!

Step 4: Edit the /etc/postfix/generic file

This file maps the local user address (usually of the form yourid@machine.local) to a valid Internet email address you would like to use when sending mails to the outside world. In our case, it would basically map your Unix user name to the Gmail ID.

$ cd /etc/postfix
$ whoami                # This will provide your local user name
$ hostname              # This will provide your machine name
$ sudo cp generic generic.orig
$ sudo vim generic
$ sudo postmap generic

In the file, add the following lines at the end of the file (replacing the <username> with the output of the whoami command, and <machinename> with output of the hostname command):

# Translate my primary email address to the Gmail address
# This is ONLY for the outbound email, and does not apply to
# local email.
<yourusername>@<machinename>  <your gmail ID, e.g. user@gmail.com>
@<machinename>                <your gmail ID, e.g. user@gmail.com>

Remember to run the last command (postmap) as otherwise the changes will not be picked up!

Step 5: Edit/Create the /etc/postfix/sasl/passwd file

In this step, we store the SMTP authentication (user ID and password) for Gmail, so that postfix can connect as any other SMTP client to Gmail via an authenticated session.

Note that the file may not exist prior to this step, in which case we will create it.

$ sudo mkdir -p /etc/postfix/sasl    # In case the directory does not exist
$ cd /etc/postfix/sasl
$ sudo vim passwd
$ sudo postmap passwd

Create the following file, replacing <gmailusername> with the ID you use for Gmail (with the “@gmail.com” added at the end), and <gmailpassword> with the password you use to login to Gmail.

[smtp.gmail.com]:587    <gmailusername>:<gmailpassword>

Note that if you use two-factor authenication with Google, then the password to use will be a new application specific password generated via Google’s account settings.

Final Step: Test the settings

We are now good to go. Lets test our settings from the terminal:

$ cd /System/Library/LaunchDaemons
$ sudo launchctl load -w org.postfix.master.plist
$ cd ~                             # Just to be safe, move to your home directory
$ mail <your_id>  # Output of the `whoami' command
# Type in a test email and hit Control-D on a new line
$ mail
# Check whether the email has arrived. Hit 'q' on the '?' prompt to quit

$ mail <your gmail ID>       # Lets now try to send an external mail.
# Type in a test email and hit Control-D on a new line

After the second step above, check your Gmail account for the test mail. If it has arrived, then we have a good configuration.

Summary

Setting up the postfix system on OSX is not particularly hard, but does require some steps. Also, this is just the basic setup to get things up and running. Postfix is an industrial strength mail server has a lot of features (and a corresponding number of configurations). Thankfully, the documentation at http://www.postfix.org/documentation.html is pretty good.

For more details on this specific setup, additional documentation is available at http://www.postfix.org/SOHOREADME.html.

[Updated on 19th Feb 2012]: Corrected a typo.  Thanks to jamrok for pointing it out.

About these ads

Actions

Information

73 responses

20 02 2012
jamrok

Hello,

Thanks for sharing this, i’ve been lookin for such precise instructions. smpt, postfix, sendmail can be very very tricky to configure. Anyway i have one issue . I’m a on mac os x lion 10.7.3 FYI. On step 5 i modified the passwd file accordingly, but when i hit , sudo portmap passwd i get this error message : portmap: command not found . i tried to find the command with : locate portmap and which portmap but the system can’t find any portmap binaries on my os . Do you know if it’s a package messing ? or something else ?

20 02 2012
evolve75

Hi Jamrok,

I am happy that this was useful to you. Also, my apologies for the typo around the ‘portmap‘ command. It should actually be ‘postmap‘! Many thanks for pointing this out, and hopefully you should be able to now proceed with setting up postfix.

9 04 2012
dhempler

Great tutorial. Worked the first time.

Thanks!

9 04 2012
dhempler

Great tutorial.

Thanks!

17 04 2012
nwwells

Thanks so much for this. I had almost broken down an spent too much money on a test server app. Thank you again!

17 04 2012
nwwells

Thanks so much for this! I almost broke down and purchased a too-expensive test server app. Thanks again!

17 04 2012
nwwells

I just found I had to do a tweak to get this working with the web app I’m developing in grails:

Comment out the line that looks like this:
imap_submit_cred_file = /etc/postfix/submit.cred

17 04 2012
nwwells

Also, I figured out how to rewrite all outbound addresses to your own address:

1) in /etc/postfix/, create a file (rewrite) with these contents:
/.*/ your.email@gmail.com

2) parse this configuration in main.cf:
smtp_generic_maps = regexp:/etc/postfix/rewrite

3) reload postfix:
sudo postfix reload

18 04 2012
kankei71

Very interesting tutorial. Unfortunately, it does not work for me. tail -f /var/log/mail.log shows the error below. It says that the username and password are not accepted, which is weird as I followed the tutorial entering the username and password with which I connect to my gmail account. Checked twice, no error.
Would you have any advice? Thanks in advance.

****
Apr 17 21:36:07 mbp-i5 postfix/smtp[86224]: setting up TLS connection to smtp.gmail.com[173.194.70.108]:587
Apr 17 21:36:07 mbp-i5 postfix/smtp[86224]: certificate verification failed for smtp.gmail.com[173.194.70.108]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Apr 17 21:36:08 mbp-i5 postfix/smtp[86224]: Untrusted TLS connection established to smtp.gmail.com[173.194.70.108]:587: TLSv1 with cipher RC4-SHA (128/128 bits)
Apr 17 21:36:09 mbp-i5 postfix/smtp[86224]: 043ED1CBB41B: to=, relay=smtp.gmail.com[173.194.70.108]:587, delay=8.8, delays=0.01/0.2/8.6/0, dsn=4.7.1, status=deferred (SASL authentication failed; server smtp.gmail.com[173.194.70.108] said: 535-5.7.1 Username and Password not accepted. Learn more at?535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 w10sm46501085wiy.3)

18 04 2012
evolve75

Interesting. Do you have two-factor authentication enabled in Google? (http://support.google.com/a/bin/answer.py?hl=en&answer=175197). If yes, you will need to generate a new application specific password, and use that instead of the password you would normally use at gmail.com.

Also, it might be that you have a security certificate installed in your TLS setup that is expired, or is causing issues.

18 04 2012
kankei71

Very interesting tutorial. Unfortunately, it does not work for me. tail -f /var/log/mail.log shows the error below. It says that the username and password are not accepted, which is weird as I followed the tutorial entering the username and password with which I connect to my gmail account. Checked twice, no error.

Would you have any advice? Thanks in advance.

****
Apr 17 21:36:07 mbp-i5 postfix/smtp[86224]: setting up TLS connection to smtp.gmail.com[173.194.70.108]:587
Apr 17 21:36:07 mbp-i5 postfix/smtp[86224]: certificate verification failed for smtp.gmail.com[173.194.70.108]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Apr 17 21:36:08 mbp-i5 postfix/smtp[86224]: Untrusted TLS connection established to smtp.gmail.com[173.194.70.108]:587: TLSv1 with cipher RC4-SHA (128/128 bits)
Apr 17 21:36:09 mbp-i5 postfix/smtp[86224]: 043ED1CBB41B: to=, relay=smtp.gmail.com[173.194.70.108]:587, delay=8.8, delays=0.01/0.2/8.6/0, dsn=4.7.1, status=deferred (SASL authentication failed; server smtp.gmail.com[173.194.70.108] said: 535-5.7.1 Username and Password not accepted. Learn more at?535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 w10sm46501085wiy.3)

18 04 2012
kankei71

My bad, I did not remove the signs.
Now working perectly.
Thank you for this great tutorial

29 04 2012
cposey

This is a FANTASTIC tutorial for Mac OS X Postfix setup. I spent many years setting up Postfix from scratch on several Linux server and this is by far the most painless setup and well written instructions I have seen. I especially appreciate you included info pertaining to Google Two-Step Authentication. I thought for sure when I started this setup I was going to run into that as a snag down the road. Nope – you thought of it. Much appreciated for this great article you wrote.

14 05 2012
Joseph Mornin

Postfix won’t work properly until you configure the submit.cred file. Instructions are here: https://discussions.apple.com/thread/3247974?start=0&tstart=0

Thanks for the tutorial!

14 05 2012
cposey

Works fine for me without the submit.cred mods.

14 05 2012
Joseph Mornin

It’ll send mail using the instructions in this tutorial—but you won’t be able to telnet successfully, and you won’t be able to connect to the mail server as localhost to send mail (e.g., from Python’s smtplib: http://docs.python.org/library/smtplib.html).

14 05 2012
cposey

Hmmm… I’m using it to send mail via shell scripts via localhost and it works fine. Is that different.

14 05 2012
Joseph Mornin

Yes, you’re probably using “mail” from the command time. I’m talking about connecting to the mail server. What happens when you run “telnet localhost 25″?

14 05 2012
cposey

Ok – - I see – telnet yields “Connection Refused”

Following the instructions you listed – you create the submit.cred file with format:

host|user|password

Would the host be listed as “localhost”

Also – isn’t that one big burrito to be hanging out there with your password in cleartext?

14 05 2012
Joseph Mornin

You don’t actually need to include any credentials in the submit.cred file—it just needs to exist, and the permissions need to be set properly, and it must include this line: “submitcred version 1″

It’s a slight security risk, but setting the permissions with “chmod 600″ ensures that you’re the only one who can access the file.

14 05 2012
cposey

Great! Thanks for that clarification.

14 05 2012
cposey

All good now – telnet connection accepted.

25 05 2012
Valerie Lynn

Thank you for posting about submit.cred!

25 05 2012
Valerie Lynn

Thank you for your step-by-step instructions!

2 06 2012
Sonny Horton (@SonnyHorton)

Excellent tutorial – thank you. I found that when I attempted to launch postfix initially with the new settings, that I received a “No socket()” error. Digging through the logs, I could see that postfix hadn’t been running for two days. I wasn’t sure how to properly resurrect the daemon, so I resorted to the old holdover from my windows days and restarted the machine. Once complete, postfix was running properly and everything worked as advertised – thanks again!

25 06 2012
Enabling postfix « Oceanside Coding

[...] the S.M.A.R.T. monitoring daemon can let me know when a problem occurs with one of the disks. Here is very detailed guide on how to setup the postfix. Share this:Like this:LikeBe the first to like [...]

28 06 2012
Alex

Hi there
Whereas sending local mails works fine, outbound messages won’t get delivered with a: host smtp.gmail.com[173.194.70.108] said: 530-5.5.1
Authentication Required. Learn more at 530 5.5.1
I followed your instructions and double checked the passwd file in /etc/postfix/sasl

I’m almost sure I’m missing something obvious.. but what?

28 06 2012
evolve75

Alex,

Did you run the postmap command after editing the passwd setting file?

sudo postmap passwd

28 06 2012
Alex

Yes I did (several times, just to be sure) ;)
I somehow have the feeling that my main.cf might be the cause… Before I found this tutorial I played around with the lion mailserver configuration tool..
Is there any default main.cf that I could check mine against?

29 06 2012
evolve75

Alex,

That might be one of the reasons. Unfortunately, I am not sure of the changes that the Lion mailserver tool makes; however, I assume it makes a backup of the file somewhere (usually in the same directory, with a different extension). Your best bet is to look at the tool’s documentation and find out if it makes a backup, and then diff the backup with the current file to check on any changes.

Another thing that you might want to check is on whether you are using the right password (especially if you are using two-factor authentication with Gmail, where you will need to generate an application specific password, and use that).

1 07 2012
Alex

After searching around a bit I found a default main.cf into (which I had to complete with a few paths etc.) but after that everything started working like a charm :)

thanks again!

10 07 2012
johnny

This tutorial is great! I am interested in learning more about unix and being able to control my mac more fully, what books would you recommend reading…

10 07 2012
evolve75

Johnny,

Great that you found the tutorial to be useful. There are many (literally, thousands) of books on Unix. Many of the books also focus on Linux, which can be useful to an extent for understanding the OSX Unix underpinnings. A good and comprehensive book is the A Practical Guide to UNIX for Mac OS X Users. Another good resource is the unixFAQ for OS X.

I actually moved from being a Linux user (Slackware) to the Mac, partly because the new environment still lets me use the shell and a true Unix (BSD flavored).

Hope you have a good time ahead with the Unix foundations of OSX!

13 07 2012
Don Morrison

Thanks for the potentially useful tutorial (I’ve not gotten it to work for me yet, but I’m still trying).

I notice a couple minor typos you might want to correct: in a couple of places you’ve accidentally omitted the ‘sudo’ when making a backup copy.

Anyway, thanks. Back to figuring out why it’s not worked for me yet….

13 07 2012
Don Morrison

Just to follow up: works great once I spell “noanonymous” correctly!

Thanks again for the tutorial. Saved me hours of frustration!

13 07 2012
evolve75

Don,

Thanks for catching the missing ‘sudo’. I have updated the post accordingly.

18 07 2012
Daniel

Thank you for this tutorial, even though it hasn’t been of use to me yet. I’m a complete newbie so I guess I should maybe not be trying this as I don’t fully understand what I’m doing.

I’m trying this on a 10.6 machine. Postfix delivers the mails fine locally but not at all when I try to send them to an external address. The strange thing is that I don’t even get a delivery failure notification which I used to get before I went through this process.

24 07 2012
Postfix für Emailversand über GMail unter Lion OS X aktivieren - Thilo Brandt

[...] Apple eigene MTA postfix in Lion OS X für den Versand an externe Adresse aufsetzen will, sollte diese Anleitung von /usr (auf englisch!) unbedingt lesen. Sie beschreibt sehr ausführlich und gut den Einsatz [...]

29 07 2012
Sushma Satish

Worked like a charm, on Mountain Lion, had to do:
sudo launchctl stop org.postfix.master
sudo launchctl start org.postfix.master

5 08 2012
Send to Kindle — Nathan Nutter

[...] #444444; }Skip to content Nathan Nutter Send to KindlePosted on August 4, 2012. I just setup postfix to send mail through my Gmail account so that I could use the mail command to send documents to [...]

15 08 2012
Robert Vidler

It works great.

My question is – I have postfix running the relay on another server. I have a UPS I want to send me email alerts. I want to use the postfix server to do that because the UPS must use a local SMTP server to push.

What is the local smtp server address I use? From address? I’m getting confused if I should use gmail or the local postfix accounts.

17 08 2012
Jeremy

Many many thanks! Worked perfectly. I even got a nice backlog of emails I’d tried to send from a few websites I’d been working on locally.

20 08 2012
lon

Everything works except starting postfix on demand. I need to “sudo postfix start”. I’ve tried rebooting, launchctl unload and load sequences, but the OnDemand thing doesn’t seem to work. Checked and re-checked org.postfix.master.plist. Any ideas for troubleshooting would be appreciated.

25 09 2012
cposey

Same problem here – after a restart I have to manually stop/start postfix to get it working – does anyone have a solute to get the launch agent running again?

10 09 2012
Configuration issue when sending email on Mountain Lion using Postfix - feed99

[...] when that didn’t work, I followed that one instead: http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-…. The basic steps in the blog post is to teach you how to send out using GMail by doing some [...]

10 09 2012
Configuration issue when sending email on Mountain Lion using Postfix | Jisku.com - Developers Network

[...] when that didn’t work, I followed that one instead: http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-…. The basic steps in the blog post is to teach you how to send out using GMail by doing some [...]

12 09 2012
Configuration issue when sending email on Mountain Lion using Postfix | question code

[...] when that didn’t work, I followed that one instead: http://slashusr.wordpress.com/2012/02/14/enabling-postfix-for-outbound-relay-via-gmail-on-os-x-lion-…. The basic steps in the blog post is to teach you how to send out using GMail by doing some [...]

15 09 2012
Martin

Awesome tutorial! Worked the first time. Thanks a lot!

15 09 2012
cposey

After upgrading to ML I Postfix started throwing this error:

send-mail: fatal: chdir /Library/Server/Mail/Data/spool: No such file or directory

I followed these direction to get it up an running again (basically recreating dir and changing permissions):

https://discussions.apple.com/thread/4136501?start=0&tstart=0

Everything seems to be working fine but I am still seeing this non-critical error:

postfix/postfix-script: warning: group or other writable: /Library/Server/Mail/Data/mta

Is there something I can do to alleviate that last error?

22 09 2012
Mike Newman

Doesn’t work for me, either:

aliases:

root: mnewman

generic:

mnewman@bleach.local mygmail@gmail.com
@bleach.local mygmail@gmail.com

But all mail sent to both root and mnewman ends up in the mnewman local mailbox. The mail never gets forwarded to the remote gmail address. So, it appears that the aliases file is working, but that generic is not.

I have run newaliases and postmap generic and postfix reload.

bleach:postfix mnewman$ hostname
bleach
bleach:postfix mnewman$ whoami
mnewman

== mail.log ==
Sep 22 10:06:25 bleach postfix/pickup[1225]: 395323508C4A: uid=502 from=
Sep 22 10:06:25 bleach postfix/cleanup[1230]: 395323508C4A: message-id=
Sep 22 10:06:25 bleach postfix/qmgr[1226]: 395323508C4A: from=, size=321, nrcpt=1 (queue active)
Sep 22 10:06:25 bleach postfix/local[1232]: 395323508C4A: to=, orig_to=, relay=local, delay=0.06, delays=0.04/0.02/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
============

This on a Mac running OSX 10.8.2.

What did I do wrong?

3 10 2012
Daza Grohovaz

Hello,

i use Mountain Lion with the Server Application.
looking in the mail.log file, i just realized that MacOSX Server didn’t set all rights like i should do…

1. look in the log file

tail -f /var/log/mail.log

2. if you get this message, you have the same problem that i had

Oct 3 11:48:54 MacOsX.Server postfix/postfix-script[59779]: warning: not owned by _postfix: /Library/Server/Mail/Data/mta/./guid_device_maps.plist

3. check the rights and privileges of the file guid_device_maps.plist

sudo ls -al /Library/Server/Mail/Data/mta/./guid_device_maps.plist
-rw-r—– 1 root mail 181 Sep 18 07:40 /Library/Server/Mail/Data/mta/./guid_device_maps.plist

4. change the owner to _postfix user

sudo chown _postfix /Library/Server/Mail/Data/mta/./guid_device_maps.plist

5. check your changes ;)

sudo ls -al /Library/Server/Mail/Data/mta/./guid_device_maps.plist
-rw-r—– 1 _postfix mail 181 Sep 18 07:40 /Library/Server/Mail/Data/mta/./guid_device_maps.plist

6. open the Server Application, go to Email, check the Authentication method, i set it as “Automatic”

7. finally restart it switching on/off

sorry if the description isn’t 100% correct, i have my system in german, but i think you know what i mean…

regards

5 10 2012
Jim Lindsay

Evolve 75, great tutorial. It worked well for me in ML.
I am quite new to Unix and Postfix in particular.
How can I set this up so that users on the network can connect to the postfix server and relay via smtp.gmail.com to their own accounts? This is to let them send scanned documents from a machine which does not support TLS and, therefore, cannot send direct to their gmail accounts.

Best wishes

Jim

12 10 2012
How to send mail through PostFix on Mac OSX Mountain Lion | Dixit Design

[...] See also: How to enable PostFix mail on OSX so you can send mail or gmail through the command line [...]

20 10 2012
Jay

When I get to this step:

sudo /usr/sbin/postfix set-permissions

I’m getting this error:

chown: /usr/share/man/man1/postalias.1.gz: No such file or directory

11 11 2012
Antti Makkonen

Thank you so much for this! Saved me a ton of digging.

21 11 2012
Naomi M

saved me a lot! Thank you sooo very much!

25 11 2012
maui_kihei (@maui_kihei)

Mountain Lion with Mamp and mail still doesn’t work.

Man this is fascinating and tought at the same time.

30 11 2012
ajaxiom (@Ajaxiome)

Hi,
thanks for the tutorial.
I’m on Os Lion, I perform all the stuff described.
When I send an email with email myUserName it works (in Local)
When I try to send to my gmail adress, the field ‘to’ in my mail is …@new-host.home
And then it is rejected by gmail server.
Do you know how to configure postfix in order it create a correct adress ?
Thanks

30 11 2012
evolve75

Hi,

This usually happens if the changes in the /etc/postfix/generic file have not been applied/picked up by Postfix. Can you recheck the step 4, and ensure that the postmap command has been run correctly?

25 12 2012
M. P. de Sá Pereira (@muziejus)

Worked well on 10.8.2 once I used the right syntax in the launchctl command and replaced both instances of “smtp.gmail.com” with an IP address for it. For some reason, I was getting this error:

Dec 24 22:33:17 box.home postfix/smtp[60826]: AD5AF48D2722: to=, relay=none, delay=264, delays=251/0.2/12/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=smtp.gmail.com type=AAAA: Host not found, try again)

26 12 2012
takumahabuuma

I got it to work perfectly on my server thank you for this! I wondered what kind of changes I would need to make this to work on a generic SMTP server (via SSL). Please let me know.

26 12 2012
Getting mail() function to work on PHP via OS X Server | All things me

[...] the mail function of PHP to work with my OS X Server. After a lot of searching around, I found this website. I followed it step by step, and found that it worked straight away. Note that I used Gmail SMTP [...]

7 01 2013
carbontax

Nobody else seemed to have this problem, but after following this (excellent) guide I still had an error in /var/log/mail.log when sending external emails through the smtp relay. Delivery of local mail was not affected.


error: unsupported dictionary type: sdbm

fatal: dictionary sdbm:/var/lib/postfix/smtp_tls_session_cache is not a regular file

The fix is to edit /etc/postfix/main.cf to disable sbdm and enable btree for the TLS request cache.


smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
#smtp_tls_session_cache_database = sdbm:/var/run/smtp_tls_session_cache

20 01 2013
Joe

Tutorial was easy enough to follow, but I can’t seem to get it working. Getting the following error:

Jan 20 10:17:36 unknownf81edfe4dce3 Mail[1098]: [ mechanism: PLAIN security layer: no] Failed to start the SASL connection

21 01 2013
Joe

Let me provide a little further info here: My primary reason for enabling postfix was so that I could test the outgoing emails for a website that I’m developing on my local machine. While looking at some of the difficulties others were having, I started postfix with – sudo postfix start. During the process I received the following warnings:

$ sudo postfix start
postfix/postfix-script: warning: not owned by root: /etc/postfix/aliases copy
postfix/postfix-script: warning: not owned by root: /etc/postfix/generic copy
postfix/postfix-script: warning: not owned by root: /etc/postfix/main.cf copy
postfix/postfix-script: warning: not owned by root: /etc/postfix/sasl
postfix/postfix-script: warning: not owned by root: /etc/postfix/sasl/passwd
postfix/postfix-script: warning: not owned by root: /etc/postfix/sasl/passwd.db
postfix/postfix-script: starting the Postfix mail system

However, after starting Postfix, I found that the outgoing mail from the website I was developing began working, but I still could not sent email from the terminal and I’m still seeing the error log message reported in my original post.

21 01 2013
evolve75

Joe,

can you check the ownership of the files under the /etc/postfix directory? They should belong to root user, and the wheel group.

If they belong to another user (as is being pointed out by the error message), then use the chown Unix command to change the ownership to root.

21 01 2013
Joe

Thank for the quick feedback, especially on a Sunday with playoff football.

I changed the root ownership and was able to successfully send an internal email ($ mail # Output of the `whoami’ command), but I still cannot send an external email through gmail from terminal. The problem seems to be that the local user address is not mapping to a valid Internet email address. (I did run postmap after editing the generic file.) The returned email shows that postfix is attempting to send the email to:

@unknownf81edfe4dce3.localhost

vice

@gmail.com

21 01 2013
evolve75

Well, Steelers got out pretty early this year … so football has been somewhat of a lower priority :-)

Can you check if your main.cf file has the line:
smtp_generic_maps = hash:/etc/postfix/generic

in it?

You may also want to restart postfix to see if the setting takes (launchctl https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/launchctl.1.html) should allow you to restart the daemon pretty quickly.

22 02 2013
sasha

Thanks for the detailed steps. Just one thing I had to correct on my computer:
This line below, whenever it is used
/System/Library/LaunchDaemons
needs to be replaced by
/system/library/LaunchDaemons
because my system and library directories are all small letters.

9 03 2013
Mark

if you replace this section of the .plist
ProgramArguments

master
-e
60

with this
KeepAlive

it keeps the service running otherwise it shuts down after 60 secs

16 06 2013
ocombita

Hi evolve75, Nice Tutorial!! But I’m getting this in the mail log:

relay=smtp.gmail.com[74.125.130.108]:587, delay=2.2, delays=0/0/2.2/0, dsn=4.7.8, status=deferred (SASL authentication failed; server smtp.gmail.com[74.125.130.108] said: 535-5.7.8 Username and Password not accepted. Learn more at?535-5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257?535 5.7.8 {BADCREDENTIALS} x52sm14029434yhh.18 – gsmtp)
Jun 15 19:33:50 localhost postfix/master[299]: master exit time has arrived

Can you help me?
Thanks!

16 06 2013
evolve75

Ocombita,

Can you recheck the user ID and password? Specifically, the user ID does need to have the “@gmail.com” fragment at the end. Also, if you have enabled Google’s two-factor authentication, then you will need to generate an application specific password for using in Postfix, as the web password will not work.

17 06 2013
ocombita

Ok! My fault!.. Thanks for this excellent and easy to understand tutorial!
God bless you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: