# Creating a script for sending SMS

**URL:** <https://forum.mikrotik.com/t/creating-a-script-for-sending-sms/172627>\
**Category:** Scripting\
**Created:** [January 10, 2024, 11:08am UTC](https://forum.mikrotik.com/t/creating-a-script-for-sending-sms/172627 "2024-01-10T11:08:29Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [March 2, 2024, 1:07pm UTC](https://forum.mikrotik.com/t/creating-a-script-for-sending-sms/172627/14 "2024-03-02T13:07:31Z")

</div>

Can’t tell where is the issue regarding removing SMS, try to upgrade ROS to 7.14, there is some fix in [7.14](http://forum.mikrotik.com/t/v7-14-3-stable-is-released/174007/1) regarding SMS removal:

> \*) modem - fixed SMS removal (introduced in v7.13);

here is script that retries removing SMS in recursion until no error with max retry count 10, controlled by _maxRetry_ variable:

```plaintext
:local removeAllSMS do={
  :do {
    /tool/sms/inbox/remove [find]
  } on-error={
    :if ($retryCnt < $maxRetry) do={
      $removeAllSMS removeAllSMS=$removeAllSMS retryCnt=($retryCnt + 1) maxRetry=$maxRetry
    }
  }
}

:global sendingSMS
:if (!$sendingSMS && [/tool sms inbox find where message ~"1237"]) do={
  :set sendingSMS true
  :do {
    /tool/sms/send Vivacom-LTE phone-number="1237" status-report-request=no message=traffic
  } on-error={
    :set sendingSMS false
    :local errMsg "Send SMS for Traffic reset failed"
    :log error $errMsg
    :error $errMsg
  }
  :log info "Send SMS for Traffic reset"
  $removeAllSMS removeAllSMS=$removeAllSMS retryCnt=1 maxRetry=10
  :set sendingSMS false
}

```

---

_[View the full topic](https://forum.mikrotik.com/t/creating-a-script-for-sending-sms/172627)._
