Outlook to Skype SMS
Thursday, March 11th, 2010I 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 to put it all together:
- 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.
- 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.
- The VBA will call skype and send the SMS message
Installation of outlook VBA code
- Add the code below to an outlook module
- Change the phone number to be your phone number (A future feature might be to include the phone number in the email subject and set this dynamically)
- Add a reference to the Skype4COM object in the module.
Running the solution
- Have outlook open, running and make sure that macros are enabeld.
- Have Skype open and logged in. (and have some credit for sending sms!) (it is possible to launch skype from the VBA script but I’m still tinkering with this to get it working reliably)
- Wait for email’s to arrive.
The Code
Sub SendSMSRule(Item As Outlook.MailItem)
Dim strContact As String
strContact = "+441234567890" 'Your phone number
subSendSMS strContact, 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
objSkype.Attach , True
Set objSMS = objSkype.CreateSms(smsMessageTypeOutgoing, strRecipients)
With objSMS
.Body = strMessage
.Send
End With
KillObjects:
Set objSMS = Nothing
Set objSkype = Nothing
End Sub