×
Home RSS feed info
Mail - use postfix for macOS, MAMP and Hugo

Mail, macOS - Postfix configuration for MAMP web server

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 .

Warning - macOS Ventura

<update Mar 2, 2023>

Unfortunately, these instructions no longer work under macOS Ventura. I had to wipe and reinstall my new MacBook Pro with M2 Pro. Postfix sent wrong requests to my mail provider and they blocked the used mail address after multiple retries. I could not undo this in the Postfix configuration either.

If you have deeper knowledge of the Postfix configuration and the installation works for you under macOS Ventura, I would be grateful for a corresponding comment.

</update>

Why do I need a local email server for my Hugo project?

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.

Configuration - Postfix macOS

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.

<update Jan 16, 2023 >
My beloved MacBook Pro from mid-2015 is unfortunately only running macOS Monterey, in the currently latest version 12.6.2. But the configuration still works. If today I would be faced with the adventure (for a non-administrator) of configuration, this info would have reassured me somewhat.
</update>

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 ctrl X.

/etc/postfix/main.cf

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.

/private/etc/postfix/master.cf

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

/etc/postfix/sasl_passwd

sudo nano /etc/postfix/sasl_passwd

The password is stored in the file sasl_passwd. Simply add the following line with your data.

xxxx.your-smtp-server.com:587 my-mailadrdess@example.com:your-secure-smtp-password

Various other instructions

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

Configuration - MAMP

The php.ini of the PHP version used must now be adapted. In my case, I replaced php[version.you.use] with php7.4.12. The 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.

nano /Applications/MAMP/conf/php[version.you.use]/php.ini

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 = your-mail-address@example.com

; 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 your-mail-address@example.com

After saving the php.ini you should restart the MAMP server.

Display SMTP log as stream

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.

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 your_another_email@example.com

Important additional information

If you change your SMTP password for the email address, you must also change the password in /etc/postfix/sasl_passwd.

In the Apple Mail programme, under | Settings | Accounts | Your email address | Server settings | the name of the outgoing email server (SMTP) is extended by the Mail programme with (offline). In other words, Sendmail or Postfix is no longer started.

The first step to fix the problem is to change the password in the sasl_passwd. Then execute the statements from the section - Various other instructions - except for the last two sudo statements, because Postfix is no longer started at this point. Use sudo postfix start to start the Postfix mail system.

By changing the mail server configuration manually, you are forced to carry out these steps for the manual changes when changing the e-mail password. Then restart the Apple Mail application.

Conclusion

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 for me locally up to version macOS 12.6.3. 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.

Starting with macOS Ventura I have problems with the postfix configuration. Only by deleting and reinstalling the OS I could fix the error.

List of links to this post

This might also interest you

Update:  |
6 minutes to read
0
This post was created with Hugo version 0.115.2.

With the German language setting, comments are not displayed in the English version of the website and vice versa.

© 2023 - Frank Kunert  -  About me