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.
In this case we did an experiment. We have a router in the office which we want to control from home. Let’s say we have two email addresses in Gmail and the router with dynamic IP Address is in your office. First email address is [email protected] and second email is [email protected]
How to send dynamic IP Address to email:
- First we need to configure the router to send emails.
- Then we need to change security settings in Google Account to allow the router to use the Gmail.
- We have to create a script on the router to detect and send us IP Address information.
- We can use the scheduler option to send IP Address info eg every 24 hours.
- And we can force the router to send us IP Address info each time the IP Address changes.
How to configure Mikrotik RouterOS to send mail:
- Open Winbox and login to the router.
- Click Tools then click Email.
- In Server: enter ip address 22.214.171.124 .
- Enter port 587.
- Start TLS, choose Yes.
- In the From field enter <[email protected]>.
- In User field enter [email protected].
- Below enter Gmail password for email: [email protected].
- If the email is not sent go to Google account and allow Mikrotik access to email.
How to change security settings in Google Account to allow the router to use the Gmail:
- Go to https://myaccount.google.com/security. On Less secure app access section switch to On, (Use another device to change account security settings).
- Open warning email with subject Critical security alert, click Check activity then click Yes, it was me.
I want to be clear: This action makes your account less secure, but it’s the only way it works.
Now we need a script that detects Dynamic IP from a specific Interface, and the same script sends the email to: [email protected]
How to create a script on the router to detect and send us IP Address information:
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 "Current dynamic IP address $myintnm: $myipaddr"
/ip dns static set address=$myipaddr name=router numbers=[find name="router"]
/tool e-mail send to="[email protected]" subject="Router $myintnm - current IP
address: $theaddr" body="Router $myintnm current dynamic IP: $theaddr"
"Wan"with your interface name used for internet access.
"[email protected]"with your email.
You can test this config by clicking Run Script. If you receive an email from your router, the config is working fine.
How to create a scheduler to run script everyday at 20 : 00:
- Click System then click Scheduler.
- Clcik Add.
- Enter the correct information in all the fields below.
- Name: ip-script-run-daily
- Start Date: Jan/01/2018
- Start Time:00:00:00
- Interval: 1d 00:00:00
- On Event, Enter the name of script: my_dynamic_ip
- Click OK.
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.
How to force the router to send us IP Address info each time the IP Address changes:
- 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”
- Click OK.
So it was for this matter. I know, it’s a short text to read but, it’s too long to write.