Automatically emailing my Raspberry Pi IP address on start up

Posted: April 20, 2014 by schoolpiclub in General News

I connect to my Raspberry Pi via VNC quite a lot, this was the reason I wanted to set up my Raspberry Pi to email my IP address automatically on start up.

I’ve tried before but couldn’t get it to work but today I found a different python script which worked first time. Here is how I set it up.

1. Create a python script and store it in a Directory.

I created a script and called it ‘startup_mailer.py‘ . Click the following link startup_mailer.py to view the code I used. Please note you will need to enter your email account settings where necessary, I use a gmail account.

I stored it in a directory and named it ‘Code

2. Make the startup_mailer.py python script executable.

To do this type the following command in terminal ‘sudo chmod +x startup_mailer.py

3. I now needed to add a line of code to my boot file. I use Raspbian so to access the boot file I typed in the following command ‘sudo nano /etc/rc.local

At the end of the code enter the location of your ‘startup_mailer.py’ file mine was ‘python /home/pi/Code/startup_mailer.py’. Save the changes.

Click the following link rc.local to see what your code should look like once you’ve added that line.

4. Now reboot your Raspberry Pi and you should automatically receive an email containing you Raspberry Pi’s IP address.

Advertisements

Comments are closed.