Kine's Info

What I found and what I know about Microsoft Dynamics NAV

Sending SMS from Dynamics NAV with 5 lines of code

After long time, I have found few minutes (ok, hour and something…) to test one idea I had. It is not long ago, when we switched our Exchange from older version to version 2010. Because I am using Windows Mobile 6.5 on my phone, I have noticed the new possibility to synchronize SMS from/to mobile with exchange/outlook. Bingo! If I am able to create the item in outlook from within NAV (and yes, I am able, I can create emails etc.), I can send SMS from NAV in this way. Easy!

What you need:

Outlook 2010

Exchange 2010

NAV (any version supporting automations…)

Mobile phone with Windows Mobile 6.1 (with some update) or 6.5

 

Step 1

Setup the mobile to synchronize all with the exchange, mainly the SMS. Just follow standard procedure, this blog is not about setting up the mobile phone…

Step 2

Create code in NAV, which will send the SMS. It is easy:

SendSMS(ToNumbers : Text[30];Body : Text[1000])

begin
  if ISCLEAR(OutlookApp) then
    CREATE(OutlookApp);

  MobileItem := OutlookApp.CreateItem(11); //11 – SMS, 12 – MMS
  MobileItem."To" := ToNumbers; //e.g. +420666777555
  MobileItem.Body := Body;
  MobileItem.Send(False);
end;

Where:

OutlookApp    Automation    'Microsoft Outlook 14.0 Object Library'.Application   
MobileItem     Automation    'Microsoft Outlook 14.0 Object Library'.MobileItem   

Step 3

Call the function where you need. You need to just run it under profile, which have outlook set to syncing SMS with phone. It will create the sms, and after the sms is synced into the mobile phone, the mobile phone will send the SMS for your wherever you want. If you want to have central sending machine, use the NAS or WebServices to send SMS based on some queue…

Conclusion

As you can see, you do not need to pay for some 3rd party service. You only need some mobile phone with good tarif. Of course, this is not good solution for some bulk sending, but for some standard notifications it is suitable.

Do not forget to make some maintenance of the outlook account, like deleting old sent items etc. You can do it through some code in NAV or may be somehow on the exchange.

And yes, you can read the incoming sms in similar way, just read the items from the outlook.

Some examples of usage:

Sending SMS to admin when session limit is reached (using NAS).

Sending SMS to customer when order is prepared to ship.

Generally: sending SMS when <some action> in NAV happen. :-)

  • MobileItem := OutlookApp.CreateItem(11); //11 – SMS, 12 – MMS

    Code line above ends up with error:

    This Automation variable has not been instantiated. You can instantiate it by either creating or assigning it.

  • Sorry, error in the code, remove the NOT in the condition. I have corrected the article...

  • I don't really understand what the Windows Mobile Phone has to do with it, if it's Exchange who is sending the SMS, or did I misunderstand something here?

  • The SMS is not sent by Exchange, but it is synchronized into the phone through exchange as any other items like e-mail. Phone itself than take this item and send the sms into the network. If you want to send the SMS from Exchange, you need some service provider for this. This way through phone do not need any additional service...

  • with outlook 2007 Primary Interop Assembly Reference, mobile items are not available. only with Outlook 2010 PIA Reference its available.

    so i guess Exchange 2010 is also mandatory.

    ref-msdn.microsoft.com/.../bb610278(v=office.14).aspx change outlook version for 2007

  • Ok, thanks, I assumed it but I had no time to search for some official thing about this...

  • these code is working only for windows mobile or any mobiles please clarify?

  • It depends on the features which the mobile support - if it sync with outlook and support the SMS messages syncing with outlook/exchange, than you can use it. But e.g. Windows Phone 7 is not supporting this.