Setting Up Sendmail for MacOS
This documentation should only have to be completed once per development workspace, and it is only necessary for development systems, as production environments will usually already have an email domain setup on the server.
Prerequisites
These directions are for MacOS computers only. Go to the Windows instructions if you are on Windows. Currently we do not have instructions for Linux.
Before following this tutorial, the following things should already have been setup:
- Framework App Dev workspace
- A Google account with Gmail (you may either use your personal or setup a dummy account just for your Informatics emails)
Google Account Settings
- Turn on 2-factor authentication to your Gmail account: 2-Factor Authentication
- Make an App Password calling it Sendmail: App Passwords
- There will be a 16 digit password that pops up -> this will not be saved, so you need to copy it for future steps before you close the popup. If you lose it, you can always create a new one.
PHP Configuration
Run which sendmail
, which should show you where sendmail is located (probably /usr/sbin/sendmail
). You will need to take note of that path and edit your php.ini. Find sendmail_path, make sure it's not commented out, and set it like so:
sendmail_path="/path/to/sendmail -t"
FW Setup
You also need to turn off SMTP for your local setting because it will not work correctly with gmail. Go to your global local.php
configuration file (webroot/fw-dev/config/local.php
) and add the following value to the return array:
'mail-core' => [
'config' => [
'useSmtp' => false
]
]
Note: if you already have a mail-core
property, just add the config to that array.
Postfix Configuration
This part of the guide is taken from this useful gist; the comments there may be of help if you run into issues.
- Note: these instructions use vi, but you can use whichever text editor you want.
1. Edit postfix configuration file
sudo vi /etc/postfix/main.cf
- Ensure that the following values are set:
mail_owner = _postfix
setgid_group = _postdrop
- Add the following lines at the end of the file:
# Postfix as relay
#
#Gmail SMTP
relayhost=smtp.gmail.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
# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
2. Create sasl_passwd file
sudo sh -c 'echo "\nsmtp.gmail.com:587 your_email@gmail.com:your_password" >> /etc/postfix/sasl_passwd'
Replace your_email@gmail.com and your_password with actual values. This should be the email address and app password from the Google account you will be using.sudo postmap /etc/postfix/sasl_passwd
3. Autorun postfix on boot and restart postfix
- Copy the postfix master plist out of System folder.
sudo cp /System/Library/LaunchDaemons/com.apple.postfix.master.plist /Library/LaunchDaemons/org.postfix.custom.plist
sudo vi /Library/LaunchDaemons/org.postfix.custom.plist
- Change the label value from
com.apple.postfix.master
toorg.postfix.custom
Remove these lines to prevent exiting after 60s
<string>-e</string>
<string>60</string>
Add these lines before </dict>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
- Relaunch the daemon. (Note: it may error after running the first of these commands. That should be fine.)
sudo launchctl unload /Library/LaunchDaemons/org.postfix.custom.plist
sudo launchctl load /Library/LaunchDaemons/org.postfix.custom.plist
- Check that daemon has started.
sudo launchctl list | grep org.postfix
4. Test
echo "Test sending email from Postfix" | mail -s "Test Postfix" youremail@domain.com
(changeyouremail@domain.com
to a valid email with mailbox access for easy checking).- Check mail queue and possible delivery errors with
mailq
. - Check mail log with
tail -f /var/log/mail.log
. - We also want to test using sendmail. The top answer here shows a concise way to do so.
Test from FW App
Finally, I would recommend testing from an FW app installed in your workspace. The easiest example that will send an email is creating a user or resetting a user's password in Group Control. If doing that sends an email to the email address associated with that user, then you know sendmail is setup correctly.