How to Send Email from localhost on macOS


  • To send the email from localhost we will be using Postfix which is the standard email server installed by default in MacOS.
  • Follow the steps given below to send email from localhost.



  • Open terminal and edit the file 
  • Use below command to edit the file.

        sudo vi /etc/postfix/

  • Look for the following lines in file  (They are probably separated).

            mail_owner = _postfix

            setgid_group = _postdrop

    • If above lines doesn't exist then add them in your file.
    • Now add the following lines at the very end of the file.

          #Gmail SMTP


          # Enable SASL authentication in the Postfix SMTP client.





          # Enable Transport Layer Security (TLS), i.e. SSL.




      • After adding above lines save file.

      Add your SMTP Email and Password

      • Above lines tells Postfix to use GMAIL SMTP server with Simple Authentication and Security Layer (SASL). Which will be stored in the path “/etc/postfix/sasl_passwd“. You can use any other SMTP provider (Hotmail, Yahoo, etc…). You only need to update the correct SMTP host and port.

      • Now we will create sasl_passwd file which will store your sender email and password.
      • To create sasl_passwd file, you can use following command to open it in the terminal.


                 sudo vi /etc/postfix/sasl_passwd


      • Write the following content (sender email and password)  and save sasl_passwd file.



      • Create the Postfix lookup table from the sasl_passwd file. To create lookup table use the following command.


                 sudo postmap /etc/postfix/sasl_passwd


      • This will create the file sasl_passwd.db in directory  /etc/postfix.

      Restart postfix service

      • To apply all new changes we have to start the postfix service. If postfix is already running then restart it. 


               start command - sudo postfix start 

               restart command - sudo postfix reload


      • Now, we can send the Email.

      Test the Email

      • Create a test.php file in /Applications/AMPPS/www directory and add the below code, change the sender and receiver email and test if email are sent correctly.


                $headers = 'From:sender name<>' . "\r\n" .

                 'Reply-To:' . "\r\n" .

                 'X-Mailer: PHP/' . phpversion();

      var_dump(mail('', 'Test Subject Mac', 'Test Message Mac', $headers));

      • Now you can check if you have received the email on receiver email address.


        If you are facing any issues, please open a ticket at Support.

        Was this page helpful?