Last active
May 17, 2017 10:06
-
-
Save alucard001/41f66bec1ba8216aa9472640cb0d4af0 to your computer and use it in GitHub Desktop.
Python 2 Linux send email through Gmail using SMTP
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
# Python 2 Script. It works as of 17 May 2017 | |
import os | |
if "CONNECTED" not in os.popen("/usr/bin/openssl s_client -connect 192.168.1.15:25 | /bin/grep '^CONNECTED'").read(): | |
# Note about sending email using Gmail SMTP | |
# https://www.digitalocean.com/community/tutorials/how-to-use-google-s-smtp-server | |
# http://stackoverflow.com/questions/20337040/gmail-smtp-debug-error-please-log-in-via-your-web-browser | |
# How to send email using Linux Command: http://www.binarytides.com/linux-mailx-command/ | |
# Notes about nss-config-dir: http://stackoverflow.com/questions/16799407/mailx-and-gmail-nss-config-dir | |
# How to check if remote email server is alive: https://serverfault.com/questions/131627/how-to-inspect-remote-smtp-servers-tls-certificate | |
cmd = ( "echo 'Your Server is DOWN!' | /bin/mailx " | |
"-S smtp-use-starttls " | |
"-S ssl-verify=ignore " | |
"-S smtp-auth=login " | |
"-S smtp=smtp://smtp.gmail.com:587 " | |
"-S from='My_Server' " | |
"-S [email protected] " | |
"-S smtp-auth-password='your_email_pwd' " | |
"-S nss-config-dir=/root/.mozilla/firefox/yyyyyyyy.default " | |
"-S ssl-verify=ignore " | |
" -s 'Subject Line' " | |
"[email protected] ") | |
os.popen(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note about sending email using Gmail SMTP
How to send email using Linux Command
Notes about nss-config-dir
How to check if remote email server is alive
My Works
Hong Kong Marketing Consultant
My Blog
Home Decoration
http://happinesspig.com