Skip to content

Instantly share code, notes, and snippets.

@shanep
Forked from haccks/postfix_mail_macosx.md
Last active December 4, 2023 20:57
Show Gist options
  • Select an option

  • Save shanep/94e28edcaf3ff23b5d708f4ecdc217c0 to your computer and use it in GitHub Desktop.

Select an option

Save shanep/94e28edcaf3ff23b5d708f4ecdc217c0 to your computer and use it in GitHub Desktop.
Gmail Postfix MacOS

Setting up postfix with Gmail on MacOS

  • 14.1.1 Sonoma

1. Create an App Passowrd with Gmail

2. Create a sasl_passwd file

sudo vim /etc/postfix/sasl_passwd
  • Add this to the file
smtp.gmail.com:587 [email protected]:APP_PASSWORD

Replace EMAIL with your gmail username and replace APP_PASSWORD with the App password you generated in step 1

  • Create a lookup table
sudo postmap /etc/postfix/sasl_passwd

2. Edit the main.cf file

  • Open postfix's main.cf
sudo vim /etc/postfix/main.cf
``

+ Add these fields at the end of the file 

```bash
#Gmail SMTP
relayhost=smtp.gmail.com:587
# Enable SASL authentication in the Postfix SMTP client.
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

3. Send mail

Postfix should start automatically when sending mail

Test by sending a mail

echo "Postfix setting test" | mail -s "Hello Postfix" "[email protected]"

Replace [email protected] with the email id of recipent.

Some useful commands

  • mailq : Check mails in the queue and errors if mail not sent.
  • sudo postfix flush: Flush the queue.
  • sudo postsuper -d ALL Delete mails in the queue.
  • sudo rm /var/mail/$USER Remove all mails from local host.
  • sudo postfix start Start postfix mail system.
  • sudo postfix stop Stop postfix mail system.
  • sudo postfix reload Reload postfix mail system.

References:

  1. How to send emails from localhost.
  2. Postfix auto start on Sierra for smtp relay.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment