Script on-up PPP

Hello everybody,
I’m trying to set the automatism that allows me to send the email as soon as a user connects in ovpn but every time he connects I don’t receive any email, can you help me to fix the script?
PS:I would like to avoid using scheduler / system script.
Thanks in advance

{
:local userid;
: local i;
: local realip;
: local vpnip;
: local uptime;
: local crttime;
: local crtdate;
:local userid

:foreach i in=[/ppp active find] do={
:set userid [/ppp active get $i name];
:set realip [/ppp active get $i caller-id];
:set vpnip [/ppp active get $i address];
:set uptime [/ppp active get $i uptime];
:set crtdate [/system clock get date];
:set crttime [/system clock get time];
/tool e-mail send to=nomeutente@gmail.com start-tls=yes subject=“TIME: $crtdate $crttime,USER_ID: $userid,UP-TIME: $uptime” body=“TIME: $crtdate $crttime, USER_ID: $userid; REAL-IP: $realip, VPN-IP: $vpnip, UP-TIME: $uptime”;
}
}

I use this script to send notifications to the telegram bot, maybe this can be used also for email

:local ips [/ppp active get [find name=$user] address];
:local up [/ppp active get [find name=$user] uptime];
:local caller [/ppp active get [find name=$user] caller-id];
:local service [/ppp active get [find name=$user] service];
:local comment [/ppp active get [find name=$user] comment];
:local active [/ppp active print count];
/tool fetch url="https://api.telegram.org/bot(YOURBOT_ID)/sendMessage?chat_id=YOURCHATID&text=LOGIN%0AUser: $user%0AIP Client: $ips%0ACaller ID: $caller%0AUptime: $up%0ATotal Active: $active%0AService: $service&0AComment: $comment" mode=http keep-result=no;

Hello, thanks, i tried also with api telegram but script wont run, i did not receive any notification, could i aslo put the script into scheduler?

Thanks