Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from urllib.request import urlopen
- import re
- import smtplib
- import subprocess
- # Setup our login credentials
- from_address = 'example@gmail.com'
- to_address = 'example@gmail.com'
- subject = 'Pi IP'
- username = 'example@gmail.com'
- password = 'yourpassword'
- myIP = subprocess.check_output('hostname -I', shell=True).decode('utf-8')
- print ("The IP address is: ", myIP)
- def send_email(myIP):
- # Body of the email
- body_text = myIP
- msg = '\r\n'.join(['To: %s' % to_address,
- 'From: %s' % from_address,
- 'Subject: %s' % subject,
- '', body_text])
- # Actually send the email
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.ehlo()
- server.starttls() # Our security for transmission of credentials
- server.login(username,password)
- server.sendmail (from_address, to_address, msg)
- server.quit()
- print ("Our email has been sent!")
- send_email(myIP)
Add Comment
Please, Sign In to add comment