import subprocess | |
import smtplib | |
import socket | |
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' | |
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() |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
default raspberry pi login
|
This comment has been minimized.
This comment has been minimized.
set locale
add....
|
This comment has been minimized.
This comment has been minimized.
This is awesome, might use it for something, can't think of a use yet. |
This comment has been minimized.
This comment has been minimized.
or via a cronjob
then
|
This comment has been minimized.
This comment has been minimized.
looking at it the cron job is more reliable, placing it in the rc.local file fails on wifi |
This comment has been minimized.
This comment has been minimized.
Thanks for the code you posted. On Raspberry Pi 3, Model B, I had to slightly change your startup_mailer.py script when I invoke it using Cron at booting time:
|
This comment has been minimized.
This comment has been minimized.
anassar's workaround worked for me. Then I realized I was calling the script from cron @reboot - without allowing for additional tries, apparently everything the python script needed had not loaded when the script ran and the script failed. |
This comment has been minimized.
This comment has been minimized.
Hey There. Thanks for this. Will make remote monitoring of my Pi much easier. Having an issue though. |
This comment has been minimized.
This comment has been minimized.
Hey @bereshr1! Is there any chance you are using two step verification on your gmail account? That could be the issue. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
found the solution and modified johnantoni's script. just tested and worked ! |
This comment has been minimized.
This comment has been minimized.
Hello! Sorry if i bring up this old thread but i get this error:
Any idea of how to fix it? |
This comment has been minimized.
This comment has been minimized.
The 'src' is not in list is caused by python3. Try python2 instead. |
This comment has been minimized.
create code dir
save in /home/pi/code/startup_mailer.py
make it executable
add to boot.rc
this...
and if on raspbian
this...