Skip to content

Instantly share code, notes, and snippets.

@giovanigenerali
Last active December 20, 2021 20:07
Show Gist options
  • Save giovanigenerali/39efe8760f84ed74b44a31be1ace27e7 to your computer and use it in GitHub Desktop.
Save giovanigenerali/39efe8760f84ed74b44a31be1ace27e7 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

@jbis9051
Copy link

macOS Sierra 10.12.6
Sill getting Error (TLS is required, but our TLS engine is unavailable) after running command sudo postfix tls enable-client PLEASE HELP!!!!!!

Copy link

ghost commented May 2, 2018

thank's

@happicamper
Copy link

I think this works on MacOS Sierra without the latest security patch. After I patched my machine, it displays the error above, same with @jbis9051.

@fab01
Copy link

fab01 commented Jan 10, 2019

Tnx bro! You made my day! I completely forgot to run postmap command!

@angryber
Copy link

angryber commented Jun 8, 2019

Hi bro~~
thanks the nice tutorial, however it doesn't work on my high Sierra 10.13.
I have no idea to figure the problem. so could you check my log blow and give some advices?
+++++++++++++
PKCU:~ avis$ postconf -n
biff = no
command_directory = /usr/sbin
compatibility_level = 2
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = /usr/share/doc/postfix/html
inet_protocols = all
mail_owner = _postfix
mailbox_size_limit = 0
mailq_path = /usr/bin/mailq
manpage_directory = /usr/share/man
message_size_limit = 10485760
mynetworks = 127.0.0.0/8, [::1]/128
newaliases_path = /usr/bin/newaliases
queue_directory = /private/var/spool/postfix
readme_directory = /usr/share/doc/postfix
recipient_delimiter = +
relayhost = smtp.gmail.com:587
sample_directory = /usr/share/doc/postfix/examples
sendmail_path = /usr/sbin/sendmail
setgid_group = _postdrop
smtp_always_send_ehlo = yes
smtp_sasl_auth_enable = yes
smtp_sasl_mechanism_filter = plain
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_use_tls = yes
smtpd_client_restrictions = permit_mynetworks permit_sasl_authenticated permit
smtpd_tls_ciphers = medium
tls_random_source = dev:/dev/urandom
unknown_local_recipient_reject_code = 550
PKCU:~ avis$ sudo postfix reload
Password:
postfix/postfix-script: fatal: the Postfix mail system is not running
PKCU:~ avis$

@angryber
Copy link

angryber commented Jun 8, 2019

hi guys.... finally~~~it is so weird problem, the reload function doesn't work.

https://discussions.apple.com/thread/7031086

PKCU:~ avis$ sudo postfix status
postfix/postfix-script: the Postfix mail system is not running
PKCU:~ avis$ sudo postfix start
postfix/postfix-script: starting the Postfix mail system

@giovanigenerali
Copy link
Author

@angryber

Step 6:

sudo postfix stop && sudo postfix start

or

sudo postfix reload

hi guys.... finally~~~it is so weird problem, the reload function doesn't work.

https://discussions.apple.com/thread/7031086

PKCU:~ avis$ sudo postfix status
postfix/postfix-script: the Postfix mail system is not running
PKCU:~ avis$ sudo postfix start
postfix/postfix-script: starting the Postfix mail system

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