How to set up sending email with Mamp on a Mac Mini

  |   By  |  0 Comments

What a pain in the neck!

I tried Mailhog and just couldn’t it working on my M1 Mac Mini, so I’ve gone down the Postfix route and got it working and diverting all emails to one email address.

You are going to be using the Terminal (which is in Applications > Utilities)

Open that up and type

postfix

That should give you the following error, showing it exists

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

I’m using my gmail account as the smtp server, so you will need an app specific password.

In your terminal, type or copy and paste this

sudo vi /etc/postfix/main.cf

Then your Mac password.

That will open the file up in the worst looking terminal editor ever. Scroll down and look for

mail_owner = _postfix
setgid_group = _postdrop

You edit by placing the cursor where you want to put it then the i key to go into edit mode.

Next scroll to the bottom and copy and paste this code to set up gmail as the smtp server

# Use Gmail SMTP
relayhost = smtp.gmail.com:587
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

Now you can save the file – Click on the ESC key and then type :wq – w is for save and q is for quit.

Now we need to create a gmail username/password file with you app specific password.

sudo vim /etc/postfix/smtp_sasl_passwd

Press i to start inserting and add the following

smtp.gmail.com:587 your_username@gmail.com:your_password

Click ESC key and then :wq to save and exit.

This command will tell postfix to look at that file

sudo postmap /etc/postfix/smtp_sasl_passwd

Now we need to set it up for TLS

sudo vim /etc/postfix/smtp_tls_sites

Click i to insert and add

[smtp_gmail.com]:587 MUST_NOPEERMATCH

Then click ESC key followed by :wq to save and exit

We tell postfix to understand that with

sudo postmap /etc/postfix/smtp_tls_sites

Final step to get Postfix working is

sudo postfix start

You’ll want this to start every time you start up your Mac, so type this…

sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist

That stops that file

Then you can edit it with

sudo vim /System/Library/LaunchDaemons/org.postfix.master.plist

Remove these lines.

<string>-e</string>
<string>60</string>

and add

<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>

Then you can restart that file

sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist

Check it works with

echo "Test sending email from Postfix" | mail -s "Test Postfix" youremail@domain.com

How to divert all outgoing emails to one email address

In the terminal…

sudo vim /etc/postfix/main.c

Click i to insert and add

canonical_maps = regexp:/etc/postfix/canonical-redirect

Click ESC then :wq to save and exit

Now we are going to create a file with the divert to email address

sudo sh -c 'echo "\n/^.*$/ youremail@domain.com" >>/etc/postfix/canonical-redirect'

Then this will create the file needed by postfix

sudo postmap /etc/postfix/canonical-redirect

Try this, just in case it is needed

sudo postfix reload

Give yourself a little test-email.php script to make sure it works

<?PHP
if(mail('test@test.com',"Test email Title","Lorum ipsum is the email body")) echo "Mail sent";

That should go to youremail@domain.com

You’re welcome.

name

ABOUT THE AUTHOR - ANDY MOYLE