The method to send dynamic IP Address to email is the ideal solution of providing the latest IP information. Dynamic IP address changes from time to time, so Mikrotik has the perfect solution to this matter.
To send dynamic IP Address to email, we need to follow some steps. First of all, we have to create some general configurations: to configure mikrotik mail, to create a system script for sending email with IP Address info etc.
Let’s say we have two email addresses in Gmail and router with dynamic IP Address is in your office. First email address is email@example.com and second email is firstname.lastname@example.org.
So, first let’s configure email in Mikrotik Router OS.
Open Winbox and login to the router.
Click Tools then click Email.
In Server: enter ip address 220.127.116.11.
Enter port 587.
Start TLS, choose Yes.
In the From field enter <email@example.com>.
In User field enter firstname.lastname@example.org.
Below enter Gmail password for email: email@example.com.
Now we need a script that detects Dynamic IP from a specific Interface, and the same script sends the email to: firstname.lastname@example.org.
In this case Dynamic IP is located in the interface called Wan. So, let’s create a script like this below.
Click System, click Script.
Enter name: my_dynamic_ip for new script.
Copy this code and paste in the Script field, click OK.
:local theaddr [/ip address get [find interface="Wan" disabled=no] address]
:local myipaddr [:put [:pick $theaddr 0 [:find $theaddr "/" ] ] ]
:local myintnm [/system identity get name]
:log warning "Dynamic IP Address: $myintnm: $myipaddr"
/ip dns static set address=$myipaddr name=router numbers=[find name="router"]
/tool e-mail send to="email@example.com" subject="Your_Dynamic_IP_Adress $myintnm - current IP
address: $theaddr" body="Router $myintnm Your_Dynamic_IP_Adress: $theaddr
You can test this config by clicking Run Script. If you receive an email from your router, the config is working fine.
Create a scheduler to run script everyday at 20:00.
Click System then click Scheduler.
Enter the correct information in all the fields below.
Start Date: Jan/01/2018
Interval: 1d 00:00:00
On Event, Enter the name of script: my_dynamic_ip
You can configure the router to send emails with new IP Address when the internet is interrupted or when your IP address is replaced by your ISP server.
All you need to do is find an IP address that is always active. The router will ping that IP every 5 seconds. At the moment when there is a ping Time Out for about 1000 ms, you will receive the email with the last IP Address.
You can do this through Netwatch.
Click Tool, click Netwatch then click Add.
In Host tab enter the correct information.
Host: Enter an IP Address that is always active.
In UP tab enter the name of IP script: my_dynamic_ip
In Down tab enter: log error message=”Internet disconnected”
So it was for this matter. I know, it’s a short text to read but, it’s too long to write.