Outlook to Skype SMS

I wanted to know when a process on a customer’s server had failed. In fact I wanted it to wake me up in the middle of the night so that I could fix it.

About the only usable outbound communication supported by the server is email, but my phone is not email capable (well it is, but not for work emails!).

So a colleague mentioned using MSN chat or Skype chat to send comments, and that set me wondering…

Skype has a COM library which can be used to interface with the Skype application. (A reinstall of Skype with the Extras Manager option ticked was needed to get the library installed.) The Skype4COM library allows you to send SMS. Outlook of course allows you to apply rules to incoming mail messages, and one of these allows you to run some code in a VBA module (the run a script option).

So put it all together and we have:

  1. A script on the customer’s server will monitor another script’s progress. If it detects a particular condition it will generate an email sent to my work email account.
  2. Outlook has a rule to look for specific text in the email subject (for example “ERROR”).  If it detects a suitable email, it will run a piece of VBA.
  3. The VBA will call skype and send the SMS message

Installation of outlook VBA code

  1. Add the code below to an outlook module
  2. Add a reference to the Skype4COM object in the module.
  3. Create a button in outlook that is linked to the macro SendTestSMS
  4. Create a rule in outlook that searches your incoming mail and will ‘run a script’ if it finds something. the script to run is the SendSMSRule VBA macro.

Running the solution

  1. Have outlook running and make sure that macros are enabled.
  2. Click the button you created in step 4 above and enter your phone number. The VBA app will remember your phone number, but you will want to send a test SMS, because you will probably have to ‘allow’ outlook to access Skype the first time after starting outlook.  Skype will ask you for confirmation.
  3. If Skype is not running, it will be started for you by the VBA code.
  4. Have some credit in Skype for sending sms!
  5. Wait for email’s to arrive.

The VBA Code

Public Sub SendTestSMS()
    Dim strMsg As String
    Dim strContact As String
    Dim strPhoneNumber As String

    strPhoneNumber = GetSetting("SendSkypeSMS", "PhoneNumber", "Data", "")

    strContact = InputBox("Make sure you allow Outlook to use Skype when prompted in Skype." & vbCrLf & _
                            "You will probably have to do this for every session" & vbCrLf & _
                            "Enter your mobile number (+44123456789)", "Enter Phone Number", strPhoneNumber)

    SaveSetting "SendSkypeSMS", "PhoneNumber", "Data", strContact

    If Len(strContact) = 0 Then
        Exit Sub
    End If

    strMsg = "A test message from Outlook"
    subSendSMS strContact, strMsg

    strPhoneNumber = GetSetting("SendSkypeSMS", "PhoneNumber", "Data", "")
    MsgBox "Sent a text to: " & strPhoneNumber
    SaveSetting "SendSkypeSMS", "PhoneNumber", "Data", strPhoneNumber

End Sub

Public Sub SendSMSRule(Item As Outlook.MailItem) 'Outlook will give us the mail item that matched the rule
    Dim strPhoneNumber As String

    strPhoneNumber = GetSetting("SendSkypeSMS", "PhoneNumber", "Data")

    If strPhoneNumber = "" Then
        MsgBox "You have to send a test SMS message so that I know what your phone number is!", vbCritical
        Exit Sub
    End If

    subSendSMS strPhoneNumber, Item.Subject

End Sub

Private Sub subSendSMS(strRecipients As String, strMessage As String)
    Dim objSkype        As SKYPE4COMLib.Skype
    Dim objSMS          As SKYPE4COMLib.SmsMessage

    Set objSkype = New SKYPE4COMLib.Skype

    If Not objSkype.Client.IsRunning Then
        objSkype.Client.Start
    End If

    objSkype.Attach , True

    Set objSMS = objSkype.CreateSms(smsMessageTypeOutgoing, strRecipients)

    With objSMS
        .Body = strMessage
        .Send
    End With

    objSkype.Convert.SmsMessageStatusToText (objaStatus)

KillObjects:
    Set objSMS = Nothing
    Set objSkype = Nothing
End Sub

Leave a comment