Created
September 23, 2018 21:27
-
-
Save SkaTeMasTer/ceadc0700c6bce2d60afaf649cf4dcd0 to your computer and use it in GitHub Desktop.
Send a email via google gmail.
This file contains hidden or 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
# Email IP addresses | |
import os | |
import sys | |
import smtplib | |
# CONSTANTS: | |
storage_dir = os.path.dirname(os.path.realpath(__file__)) | |
message = 'Network Change detected:\n' | |
# AUTOSET: | |
ipv4 = "" | |
ipv6 = "" | |
# SCRIPT: | |
os.chdir(storage_dir) #Move to folder | |
try: | |
with open('ip_addr', 'r') as ipfile: # Open file if it exists | |
ips = ipfile.read().splitlines() # Read into array | |
except IOError: | |
print "Could not find IP address" | |
sys.exit(1) | |
ipv4 = ips[0] #Store | |
ipv6 = ips[1] | |
print "The ipv4 address is:", ipv4 | |
print "The ipv6 address is:", ipv6 | |
msg = str(message + ipv4 + '\n\n' + ipv6) | |
fromaddr = '[email protected]' | |
toaddrs = '[email protected]' | |
username = '[email protected]' | |
password = 'gmail_password' | |
server = smtplib.SMTP('smtp.gmail.com:587') # Mail | |
server.ehlo() | |
server.starttls() | |
server.login(username,password) | |
server.sendmail(fromaddr, toaddrs, msg) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment