Community discussions

MikroTik App
 
lasek
just joined
Topic Author
Posts: 9
Joined: Wed Jul 10, 2024 12:13 pm

Script is not working after update

Wed Jul 10, 2024 12:17 pm

Hi, after update to version 7 my script stopped working, can u help me what shoud i change ?
:local array1 [:toarray " 02:C5:E1:7D:A1:09,DC:F0:50:E2:84:F7,1E:3D:59:2E:38:13,E2:B5:FA:8B:6F:B2"]
:local array2 [ :toarray "" ];

:local SendTo "mikrotik@gmail.com"
:local SendFrom "mikrotik@gmail.com";
:local PasswordMail "2374u5i6rew#^$&*";
:local SmtpServer [:resolve "smtp.gmail.com"];
:local UserName "mikrotik@gmail.com";
:local SmtpPort 465;
:local UseTLS "tls-only";
:local Subject "WARNING: Unauthorised host connected";

:foreach mac in=[/ip arp print as-value where interface="bridge3"] do={:set array2 ( $array2, $mac->"mac-address")}
:foreach mac in=$array2 do={:if ([:find $array1 $mac] >= 0) do={} else={/tool e-mail send to=$SendTo server=$SmtpServer port=$SmtpPort start-tls=$UseTLS user=$SendFrom password=$PasswordMail from=$SendFrom subject=$Subject body="Unauthorised host was connected: $mac"}}
 
elico
Member Candidate
Member Candidate
Posts: 162
Joined: Mon Nov 07, 2016 3:23 am

Re: Script is not working after update

Sun Jul 14, 2024 5:04 pm

Try to look at the script like that:
https://gist.github.com/elico/cbc25a4ea ... 174d07a0c5

It's much prettier then what you supplied.
Also test if it works.
If it doesn't work you should add some:
{
    :do { 
        :log info "works";
    } on-error={ 
        :log error ("$[:jobname] : error happened");
    }
}
Use the divide and conquer tactic.
Try to run the script adding some parts of the code at a time to see what is failing.
Maybe there was a change you are not aware of in the commands you already use.

And also you don't need the:
:local SmtpServer [:resolve "smtp.gmail.com"];
you should just use:
:local SmtpServer "smtp.gmail.com";
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 13149
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script is not working after update

Mon Jul 15, 2024 11:20 am

start-tls do not exist on v7

Replace
tls-only
with
starttls

and
start-tls
with
tls

@elico
Is useless lost time to nice format one script that contain errors and bad habit...
also this... for what?
:if (true = false) do={
:log info "works";
}
 
lasek
just joined
Topic Author
Posts: 9
Joined: Wed Jul 10, 2024 12:13 pm

Re: Script is not working after update

Mon Jul 22, 2024 1:37 pm

@rextended
i did excatly what u said and its not working

i got error " Error sending e-mail <WARNING: Unauthorised host connected>: error talking to server"


my script
:local array1 [:toarray " 08:C5:E1:71:A3:09,DC:F0:90:E2:24:F7,1E:2D:59:2E:38:13,1C:B5:1A:8B:6F:B2"]
:local array2 [ :toarray "" ];

:local SendTo "mikrotik@gmail.com"
:local SendFrom "mikrotik@gmail.com";
:local PasswordMail "password";
:local SmtpServer [:resolve "smtp.gmail.com"];
:local UserName "mikrotik@gmail.com";
:local SmtpPort 465;
:local UseTLS "starttls";
:local Subject "WARNING: Unauthorised host connected";

:foreach mac in=[/ip arp print as-value where interface="bridge3"] do={:set array2 ( $array2, $mac->"mac-address")}
:foreach mac in=$array2 do={:if ([:find $array1 $mac] >= 0) do={} else={/tool e-mail send to=$SendTo server=$SmtpServer port=$SmtpPort tls=$UseTLS user=$SendFrom password=$PasswordMail from=$SendFrom subject=$Subject body="Unauthorised host was connected: $mac"}}
Last edited by lasek on Mon Jul 22, 2024 6:14 pm, edited 3 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 13149
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script is not working after update

Mon Jul 22, 2024 2:34 pm

I can't help you with services I don't use.

I can only tell you the errors in the script, but setting Google and the correct parameters in the script is up to you.

I understand that it doesn't work anymore since you put the 7 on, but I wonder: Why did you upgrade if it worked before?

Quick fix: Put v6 back on and load the backup you made before the upgrade.
 
lasek
just joined
Topic Author
Posts: 9
Joined: Wed Jul 10, 2024 12:13 pm

Re: Script is not working after update

Mon Jul 22, 2024 6:01 pm

I upgraded bc i need wireguard which is only on version7. Before upgrade everything was working .
Thanks anyway
 
optio
Forum Guru
Forum Guru
Posts: 1133
Joined: Mon Dec 26, 2022 2:57 pm

Re: Script is not working after update

Mon Jul 22, 2024 7:20 pm

Try with port 587 and use FQDN for smtp server, not IP. replace [:resolve "smtp.gmail.com"]; with "smtp.gmail.com"
 
lasek
just joined
Topic Author
Posts: 9
Joined: Wed Jul 10, 2024 12:13 pm

Re: Script is not working after update

Mon Jul 22, 2024 11:51 pm

@optio
new error
"Error sending e-mail <WARNING: Unauthorised host connected>: DNS resolve failed"
 
User avatar
KILLPC
just joined
Posts: 12
Joined: Thu Apr 29, 2021 5:19 pm
Location: Greece
Contact:

Re: Script is not working after update

Tue Jul 23, 2024 7:48 am

@lasek

I just created an app password as described at https://support.google.com/accounts/ans ... 4156847-EU and managed to send an e-mail without issues (Ros 7.15.2)

Maybe delete your existing app password and create a new one just to make sure that the "sign in with google" action is not required.

Also consider in the future to create your own mailserver (to have complete control) to be certain that a possible new requirement/policy of gmail will not break your script.

Hope it helps!
 
optio
Forum Guru
Forum Guru
Posts: 1133
Joined: Mon Dec 26, 2022 2:57 pm

Re: Script is not working after update

Tue Jul 23, 2024 11:01 am

"Error sending e-mail <WARNING: Unauthorised host connected>: DNS resolve failed"
You have some DNS issue then. Did you setup DNS on ROS?
From ROS terminal when executed
:put [:resolve "smtp.gmail.com"]
what you get?
 
lasek
just joined
Topic Author
Posts: 9
Joined: Wed Jul 10, 2024 12:13 pm

Re: Script is not working after update

Wed Jul 24, 2024 11:58 am

@KILLPC
I made a new app password but it doesnt changed antything . I can send email from mikrotik but its not working on script

Image
Im getting message all the time on my email when I log in on mikrotik and log out
sorry for my english

Did u try use my script and can tell me its working for u ?
 
User avatar
KILLPC
just joined
Posts: 12
Joined: Thu Apr 29, 2021 5:19 pm
Location: Greece
Contact:

Re: Script is not working after update

Wed Jul 24, 2024 11:44 pm

I tried but it did not work for me.

The below works for me.
/tool e-mail
set server=smtp.gmail.com
set port=587
set tls=starttls
set from=mail@gmail.com
set user=user@gmail.com
set password=strongpassword

#Send the email
send to=mail@gmail.com subject="Testmail" body="Test"
The difference is that it configures the client first and then the command send to without variables.

Also optio said something about dns.

Is the smtp.gmail.com resovable at your mikrotik?