Skip to content

Instantly share code, notes, and snippets.

@mattbk
Forked from johnantoni/startup_mailer.py
Last active February 20, 2016 23:04
Show Gist options
  • Save mattbk/f2373c4996d9dace6693 to your computer and use it in GitHub Desktop.
Save mattbk/f2373c4996d9dace6693 to your computer and use it in GitHub Desktop.

Revisions

  1. mattbk revised this gist Feb 20, 2016. 1 changed file with 12 additions and 5 deletions.
    17 changes: 12 additions & 5 deletions start_mail_ip.py
    Original file line number Diff line number Diff line change
    @@ -5,19 +5,26 @@
    from email.mime.text import MIMEText
    import datetime
    # Change to your own account information
    to = 'me@example.com'
    gmail_user = 'test@gmail.com'
    gmail_password = 'yourpassword'
    to = 'TO@gmail.com'
    gmail_user = 'YOU@gmail.com'
    gmail_password = 'PASSWORD'
    smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(gmail_user, gmail_password)
    today = datetime.date.today()
    # Very Linux Specific
    arg='ip route list'
    p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
    data = p.communicate()
    split_data = data[0].split()
    ipaddr = split_data[split_data.index('src')+1]
    my_network_ip = 'Network IP: %s' % ipaddr
    #http://stackoverflow.com/a/9481595/2152245
    from urllib2 import urlopen
    my_ip = urlopen('http://ip.42.pl/raw').read()
    msg = MIMEText(my_ip)
    my_public_ip = '\nPublic IP: %s' % urlopen('http://ip.42.pl/raw').read()
    msg = MIMEText(my_network_ip+my_public_ip)
    msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
    msg['From'] = gmail_user
    msg['To'] = to
  2. mattbk revised this gist Feb 20, 2016. 1 changed file with 2 additions and 7 deletions.
    9 changes: 2 additions & 7 deletions start_mail_ip.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # https://gist.github.com/johnantoni/8199088
    import subprocess
    import smtplib
    import socket
    @@ -13,13 +14,7 @@
    smtpserver.ehlo
    smtpserver.login(gmail_user, gmail_password)
    today = datetime.date.today()
    # Very Linux Specific
    arg='ip route list'
    p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
    data = p.communicate()
    split_data = data[0].split()
    ipaddr = split_data[split_data.index('src')+1]
    #my_ip = 'Your ip is %s' % ipaddr
    #http://stackoverflow.com/a/9481595/2152245
    from urllib2 import urlopen
    my_ip = urlopen('http://ip.42.pl/raw').read()
    msg = MIMEText(my_ip)
  3. mattbk revised this gist Feb 20, 2016. No changes.
  4. mattbk renamed this gist Feb 20, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion startup_mailer.py → start_mail_ip.py
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,9 @@
    data = p.communicate()
    split_data = data[0].split()
    ipaddr = split_data[split_data.index('src')+1]
    my_ip = 'Your ip is %s' % ipaddr
    #my_ip = 'Your ip is %s' % ipaddr
    from urllib2 import urlopen
    my_ip = urlopen('http://ip.42.pl/raw').read()
    msg = MIMEText(my_ip)
    msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
    msg['From'] = gmail_user
  5. @johnantoni johnantoni created this gist Dec 31, 2013.
    28 changes: 28 additions & 0 deletions startup_mailer.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    import subprocess
    import smtplib
    import socket
    from email.mime.text import MIMEText
    import datetime
    # Change to your own account information
    to = '[email protected]'
    gmail_user = '[email protected]'
    gmail_password = 'yourpassword'
    smtpserver = smtplib.SMTP('smtp.gmail.com', 587)
    smtpserver.ehlo()
    smtpserver.starttls()
    smtpserver.ehlo
    smtpserver.login(gmail_user, gmail_password)
    today = datetime.date.today()
    # Very Linux Specific
    arg='ip route list'
    p=subprocess.Popen(arg,shell=True,stdout=subprocess.PIPE)
    data = p.communicate()
    split_data = data[0].split()
    ipaddr = split_data[split_data.index('src')+1]
    my_ip = 'Your ip is %s' % ipaddr
    msg = MIMEText(my_ip)
    msg['Subject'] = 'IP For RaspberryPi on %s' % today.strftime('%b %d %Y')
    msg['From'] = gmail_user
    msg['To'] = to
    smtpserver.sendmail(gmail_user, [to], msg.as_string())
    smtpserver.quit()