Skip to content

Instantly share code, notes, and snippets.

@Svastikkka
Forked from giovanigenerali/postfix-gmail-macos.md
Created December 14, 2020 11:02
Show Gist options
  • Save Svastikkka/e5403d31cac27cfdaedf559f2be1aa39 to your computer and use it in GitHub Desktop.
Save Svastikkka/e5403d31cac27cfdaedf559f2be1aa39 to your computer and use it in GitHub Desktop.
Postfix Gmail relay on macOS Sierra & macOSHigh Sierra

Postfix Gmail relay on macOS Sierra & macOSHigh Sierra

1 - Create a file to store our credentials:

sudo vim /etc/postfix/sasl_passwd

2 - Add something like this:

smtp.gmail.com:587 [email protected]:password

3 - Now run:

sudo postmap /etc/postfix/sasl_passwd

4 - Prepare the postfix main config file:

sudo vim /etc/postfix/main.cf

5 - Add/update these lines:

relayhost = smtp.gmail.com:587
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
smtp_sasl_security_options = noanonymous
smtp_always_send_ehlo = yes
smtp_sasl_mechanism_filter = plain

6 - Postfix service:

Check postfix status:

sudo postfix status
  • If postfix is not running, start the service:

    postfix/postfix-script: the Postfix mail system is not running
    
    sudo postfix start
    
    postfix/postfix-script: starting the Postfix mail system
    
  • If postfix is running, reload the service:

    postfix/postfix-script: the Postfix mail system is running: PID: XXXX
    
    sudo postfix reload
    
    postfix/postfix-script: refreshing the Postfix mail system
    

7 - Testing:

date | mail -s testing [email protected]

8 - Check the queue for any errors:

mailq

Useful:

  • To clear the mail queue: sudo postsuper -d ALL

Troubleshoot problems:

  • If you receive a message like (TLS is required, but our TLS engine is unavailable) enable tls:
    sudo postfix tls enable-client
    

Turn on less secure apps

In Gmail we must switch on the option “Access for less secure apps“, otherwise we will get the error: SASL authentication failed https://support.google.com/mail/answer/7126229?p=BadCredentials&rd=2#cantsignin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment