Guest User

Untitled

a guest
Mar 21st, 2018
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #!/usr/bin/python3
  2. from urllib.request import urlopen
  3. import re
  4. import smtplib
  5. import subprocess
  6.  
  7. # Setup our login credentials
  8. from_address = 'example@gmail.com'
  9. to_address = 'example@gmail.com'
  10. subject = 'Pi IP'
  11. username = 'example@gmail.com'
  12. password = 'yourpassword'
  13.  
  14. myIP = subprocess.check_output('hostname -I', shell=True).decode('utf-8')
  15. print ("The IP address is: ", myIP)
  16.  
  17. def send_email(myIP):
  18. # Body of the email
  19. body_text = myIP
  20. msg = '\r\n'.join(['To: %s' % to_address,
  21. 'From: %s' % from_address,
  22. 'Subject: %s' % subject,
  23. '', body_text])
  24. # Actually send the email
  25. server = smtplib.SMTP('smtp.gmail.com:587')
  26. server.ehlo()
  27. server.starttls() # Our security for transmission of credentials
  28. server.login(username,password)
  29. server.sendmail (from_address, to_address, msg)
  30. server.quit()
  31. print ("Our email has been sent!")
  32.  
  33. send_email(myIP)
Add Comment
Please, Sign In to add comment