This tutorial take you through the one more application related to IoT in which we are making a Mail server with Odinub.
Get you Odinub IP in your MailboxThe external IP address changes daily so here we are sending the latest IP address to the user through mail so user won't need to execute ifconfig
all the time.
For starting up the onboard WiFi of your Odinub please follow our another artical from here.
Step 1: Install python3This application is written in python3 so you will need python3 installed on your machine. For this you have to follow these commands.
sudo apt-get install python-devcurl –O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
Step 2: Install required packagesHere we will use SMTP. It is a simple message transfer protocol. SMTP provides the code which simplify the email communication between email servers. SMTP moves your mail on and across network. Execute following command to install the SMTP library.
pip install smtplib
Step 3: Python ScriptNow we have to write python script by executing following command.
sudo nano /home/debian/apps/secrets.py
Now you will get a new window in that write folloing code.
sender_address = "yourname@gmail.com" #write sender e-mail address
sender_password = "your password" #write password of sender e-mail address
sender_server = 'smtp.gmail.com'
sender_port = 587
recipient_address = "yourrecipient@domain.com" #write receiver e-mail address
After write the above code press Ctrl+X and then press Y.
Now execute following command and write code given below.
sudo nano /home/debian/apps/mail.py
After write the code press Ctrl+X and then press Y.
Step 4: Send the mailTest the file by executing the following command.
python /home/debian/apps/mail.py
It will display this,
And you will get mail like this,
Note: For this mail communication you have to turn ON "Allow less secure apps" in your gmail account security.
Step 5: Send the mail after booting of Operating SystemWe can also send the mail after booting process get over.
Here we have to turn on WiFi before send the and after booting gets over so for that execute following command.
sudo nano /home/wifi1.py
Now you will get new window in that write lines given below.
import os, sys
os.system("ifup wlan0")
After write the above code press Ctrl+X and then press Y.
Now follow the Step 1 and Step 2 from here.
Note: Here we have to execute two files "wifi1.py" and then "mail.py" so we have to add extra two lines for another file in "rc.local" file and it will look like this,
After edit "rc.local" file press Ctrl+X and then press Y.
Now we have to Reboot the OS by executing following command.
reboot
you will get the screen like this,
and you will get mail like this,
that's all. This small tutorial will help you to get the IP address and you can use it access the Odinub using SSH tools. Feel free to comment if you found this article helpful.
Comments
Please log in or sign up to comment.