Mail, macOS - Postfix configuration for MAMP web server
The PHP function mail() requires a working Postfix or similar mail server configuration on a local web server. This guide helps to configure Postfix on macOS. For the popular PHPMailer, the Postfix configuration and the change in the MAMP php.ini are not required. It just depends on the purpose of the mail application.
Without the instructions from Zulhilmi Zainudin from Kuala Lumpur, which he published on GitHub Gist in February 2020, my macOS Postfix MAMP configuration would have come to nothing - many thanks for that. Original post - How to send e-mail on Mac using MAMP (not PRO version) and Hotmail SMTP .
In Germany, there are legal requirements for domain holders. Everyone must provide an imprint. In addition to the address of the domain holder, an e-mail address and a telephone number of the holder must be provided. Since I don’t want to publish my telephone number on the internet, I have to provide a contact form instead. The legislator assumes that not everyone has a mail provider and therefore the contact form must be provided as a telephone number substitute.
Hugo is a static website generator. I get the dynamic for a contact form for the development by integrating the MAMP server, which also provides PHP. There are external services that offer contact forms for integration. However, I do not want to be dependent on external service providers, the costs also play a role. The legal requirements of the EU, for external services outside the EU, are very extensive to impossible to fulfil.
My current operating system version is macOS Big Sur version 11.5.1 (Intel). The latest MAMP version is 6.3, the PHP version is 7.4.12. The following configuration did not break my system and Mail still runs without problems.
Zulhilmi Zainudin wrote in his instructions “You’ll see a lot of warnings in your terminal throughout this process. That’s normal.” I had only one error and it was generated by the
main.cf and the entry
inet_protocols = ip4. After I removed this added line, no error was displayed. In this documentation, I did not include the entry.
The terminal GNU nano 2.0.6 editor used in this manual offers the key combination
ctrl O for saving. You can exit the editor with
Open a terminal and off you go …
sudo nano /etc/postfix/main.cf
Insert the following lines at the end of the file:
# MAMP postfix data myorigin = your-smtp-server.com myhostname = xxxx.your-smtp-server.com relayhost = xxxx.your-smtp-server.com:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_sasl_mechanism_filter = plain smtp_use_tls = yes smtp_tls_security_level=encrypt tls_random_source=dev:/dev/urandom
xxxx.your-smtp-server.com - enter the SMTP host name specified by your provider. This is also used in Apple Mail.
sudo nano /private/etc/postfix/master.cf
In the OS version that Zulhilmi Zainudin was using at the time, the comment sign before the
tlsmgr still had to be removed. With my macOS version, this was not necessary because the line was not commented out.
tlsmgr unix - - n 1000? 1 tlsmgr
sudo nano /etc/postfix/sasl_passwd
The password is stored in the file
sasl_passwd. Simply add the following line with your data.
The following instructions must be executed one after the other in the terminal as indicated:
sudo chmod 600 /etc/postfix/sasl_passwd sudo postmap /etc/postfix/sasl_passwd sudo launchctl stop org.postfix.master sudo launchctl start org.postfix.master sudo postfix upgrade-configuration sudo postfix reload sudo postfix flush
The php.ini of the PHP version used must now be adapted. In my case, I replaced
applications path also works on German systems. macOS works internally with the American version and only displays the name translated into the respective national language on the interface. The
mail function start from line 1002 in this version.
For macOS the
php.ini mail configuration must look like this:
[mail function] ; For Win32 only. ; http://php.net/smtp ;SMTP = localhost ; http://php.net/smtp-port ;smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = firstname.lastname@example.org ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t -i -f email@example.com
After saving the
php.ini you should restart the MAMP server.
In case of problems, the log of macOS can be displayed in real-time in a terminal window. Errors are also displayed in the log stream.
sudo log stream –predicate ‘(process == “smtpd”) || (process == “smtp”)’ –info
Send a mail in another terminal window and watch the log stream. The instruction for the terminal is:
date | mail -s test firstname.lastname@example.org
Once again, if you want to use PHPMailer instead of the simple mail() PHP function, you do not need this configuration.
The whole thing works locally for me. As I am not an administrator and have no ambitions to get involved in this area, I cannot answer any questions regarding the instructions described above.