Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alucard001
Last active May 17, 2017 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alucard001/41f66bec1ba8216aa9472640cb0d4af0 to your computer and use it in GitHub Desktop.
Save alucard001/41f66bec1ba8216aa9472640cb0d4af0 to your computer and use it in GitHub Desktop.
Python 2 Linux send email through Gmail using SMTP
# 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 smtp-auth-user=your_email@gmail.com "
"-S smtp-auth-password='your_email_pwd' "
"-S nss-config-dir=/root/.mozilla/firefox/yyyyyyyy.default "
"-S ssl-verify=ignore "
" -s 'Subject Line' "
"receiver@gmail.com ")
os.popen(cmd)
@alucard001
Copy link
Author

alucard001 commented May 17, 2017

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