replace deprecated do-on-error with onerror-do syntax

This commit is contained in:
Pothi Kalimuthu 2025-06-17 19:13:57 +05:30
parent 20a1812d1f
commit 4ab2ca4228
No known key found for this signature in database
GPG key ID: 57069303D36E3093

View file

@ -1,10 +1,19 @@
# SMS to Email
# version: 2.0
# change log
# - date: 2025-06-03
# - replace deprecated do-on-error with onerror-do syntax
# Source: https://forum.mikrotik.com/viewtopic.php?f=9&t=61068#p312202
# Note: The SMS is removed from the inbox after sent by Email and forwarded
# even if email and forward fail! So, test it often!
# use the following if email is not sent due to dns failure
# see: https://forum.mikrotik.com/viewtopic.php?p=1146199
# /ip dns static add name=[/tool/e-mail/get server] address=[:put [:resolve [/tool/e-mail/get server]]] comment="email server"
:global adminEmail
:if ([:typeof $adminEmail] = "nothing" || $adminEmail = "") do={
:log error "adminEmail is not defined or nil."; :error "Error: Check the log"; }
@ -23,12 +32,15 @@
:log info "\nSMS Received From: $smsPhone on $smsTimeStamp Message: $smsMessage"
# Send Email to $adminEmail
:do {
:onerror errName {
/tool e-mail send to="$adminEmail" body="$smsMessage" \
subject="SMS from $smsPhone at $smsTimeStamp"
} on-error={ :log error "SMS to Email Failed." }
:delay 3s
} do={
:log error "SMS to Email Failed."
:error "SMS to Email Failed."
}
:delay 3s
# Let's remove the SMS!
remove $receivedSMS
}