How to Install Mail Server on Mac OSX

In this post, I would like to share how to install mail server on Mac OSX. Having mail server is important if you need to send email from your web application in local environment. To do this, we will use Postfix.

Postfix is a Mail Transport Agent (MTA), supporting LDAP, SMTP AUTH (SASL) and TLS. In this post, We will setup Postfix to run with SMTP.


– Mac OSX (I’m using OSX Yosemite 10.10.3).
– Terminal

Postfix Installation

No need it because Postfix already exist as pre-installed on Mac OSX. Open your terminal, make sure you can see response if you type below:

$ postfix
postfix: error: to submit mail, use the Postfix sendmail command
postfix: fatal: the postfix command is reserved for the superuser

Great, then we are going to configure it to be able for sending email.

Postfix Configuration

We are going to change postfix configuration file. Run this command below:

$ sudo vi /etc/postfix/

Make sure if these lines below are exist

mail_owner = _postfix
setgid_group = _postdrop

Then, add these lines at the end of file

# Use Gmail SMTP
relayhost =
smtp_sasl_mechanism_filter = plain
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_security_level = encrypt
tls_random_source = dev:/dev/urandom

From codes above, you can see that we use Gmail SMTP for our postfix. Next step is add our gmail’s username and password.

$ sudo vim /etc/postfix/sasl_passwd

and add this line

Then run command below to create the hash db file for Postfix.

$ sudo postmap /etc/postfix/sasl_passwd

Configure the postfix daemon

$ sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist

Add these lines before </dict>


Start the postfix service

$ sudo postfix start

* Note that if you make changes in postfix configuration file (/etc/postfix/, you have to run command

$ sudo postfix reload


Here is the command you need to execute to test postfix.

$ echo "Test sending email from Postfix" | mail -s "Test Postfix"

If success, you will receive email in your inbox.


If you want to see mail queues, execute this command

$ mailq

If you want to see mail log, execute this command

$ tail -f /var/log/mail.log


Setting up mail server on Mac OSX can be done using pre-installed Postfix. Having mail server in local environment will give you advantage for your web application that have sending email feature.

  • payal padiya


    as have done the configuration and when i run the mailq it show

    local data error while talking to

    this type of error pls help

  • Andy Moyle

    Hi there, sorry to be commenting on an old post, but it should sort an issue I have
    I’ve got a terminal open and have typed in sudo vi /etc/postfix/ and it has output the contents of the file.

    But I can’t edit it! What am I doing wrong?

    • deerawan

      Have you pressed “a” after “sudo vi…..”? you should see INSERT status in the terminal

      • Andy Moyle

        I need to learn how to use vim – so typed vimtutor and saw how in the end. Thanks for the best article!

  • Chirag Vij

    It took time to reach to the final destination, but it finally received. Thanks a lot!!

    • deerawan


  • Eldwin Eldwin

    You are missing “smtp_sasl_security_options =” on # Use Gmail SMTP

  • Mikhail Lebedev

    os sierra

    $ sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist
    -bash: $: command not found

    $ tail -f /var/log/mail.log
    -bash: $: command not found

  • Shubham Gupta

    even if I am not making any changes in /etc/postfix/, I am able to send mail. so it means there is some default smtp ? am I write ?

    why do we need 3rd party smtp server like (gmail or hotmail) why not go with default ?

  • Heiko Müller

    A note for High Sierra

    You must not edit the Files in the folder /System/Library/LaunchDaemons, but copy them to /Library/LaunchDaemons before. Plus, the plist file got renamed from org.postfix.master.plist to

    So, for High Sierra, create a copy of your plist file and proceed with the copied file

    sudo cp /System/Library/LaunchDaemons/ /Library/LaunchDaemons/

  • bhupendra

    how to attach file in mac sierra using mail command

  • Umar Chaudhry

    I did exactly what you told, but got this error while testing to send email:
    (SASL authentication failed; cannot authenticate to server[]: no mechanism available)