Created
May 2, 2017 19:23
-
-
Save omiq/855fe83c8f3f6bb86e470c5fa0cbcd2a to your computer and use it in GitHub Desktop.
Send IP address via Python / Mailgun
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
import subprocess | |
import requests | |
# load API key from file | |
inFile = open('/home/pi/mailgun-api.txt', 'r') | |
api_key = inFile.readline().rstrip() | |
inFile.close() | |
# get host and IP | |
this_host = subprocess.check_output("hostname", shell=True).rstrip() | |
IP_line = subprocess.check_output("hostname -I", shell=True).rstrip() | |
# send via Mailgun | |
def send_message(): | |
return requests.post( | |
"https://api.mailgun.net/v3/chrisg.mailgun.org/messages", | |
auth=("api", api_key), | |
data={"from": "Bot <pibot@chrisg.mailgun.org>", | |
"to": ["chris@chrisg.com"], | |
"subject": "MY IP: " + IP_line, | |
"text": this_host + " = host and " + IP_line + " is my IP!"}) | |
print send_message() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment