Last active
April 16, 2022 03:00
-
-
Save julian-garrido/c9dfeb7c2998381b0ee7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tested in OS 10.9.5 | |
Configure Postfix for Gmail SMTP | |
Edit file /etc/postfix/main.cf | |
sudo vim /etc/postfix/main.cf | |
and add in the following below the commented out relayhosts :- | |
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_use_tls = yes | |
Generate sasl_password if not already exists | |
sudo vim /etc/postfix/sasl_passwd | |
and enter in the following:- | |
[smtp.gmail.com]:587 username@gmail.com:password | |
Run the following commands | |
sudo chmod 600 /etc/postfix/sasl_passwd | |
sudo postmap /etc/postfix/sasl_passwd | |
sudo launchctl stop org.postfix.master | |
sudo launchctl start org.postfix.master | |
Now, test the email | |
ls | mail -s "contents" your@yourdomain.com | |
(source: http://www.anujgakhar.com/2011/12/09/using-macosx-lion-command-line-mail-with-gmail-as-smtp/) | |
Include the following line in crontab after running "crontab -e". In the following example, we run it twice a day | |
03 7,19 * * * /Users/julian/src/logs/script.sh >> /Users/julian/src/logs/log_script.txt | |
Include in script.sh the command to send the email: | |
mail -s "Subjet" example@email.com < /dev/null | |
If google blocks the access to the mail server because you are using a non-secure access, you can enable less-secure access in your account settings: | |
https://support.google.com/accounts/answer/6010255?hl=es |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment