wol, ping and mail

Hey, please help
I need to write a script that will call WOL, then it will start pinging the computer and when the computer he will reply to ping and he will send an email

:local HOST "IPADDRESSOFYOURPC"
:local MAC "MACADDRESSOFYOURPC"
/tool wol mac=$MAC

# WAIT 2 minutes to boot
:delay 120

:if ([/ping $HOST interval=1 count=15] != 0) do={
	/tool e-mail send to=my@mail.tld subject="$HOST IS ONLINE" body="HOST $HOST IS ONLINE NOW" start-tls=yes
}