Microsoft Outlook is one of the most widely used email clients today, and while most people are familiar with sending and receiving emails using Outlook, many don’t know that Outlook has also had the ability to send and receive text messages. When you combine this ability with the power of Twilio SMS, it becomes very easy to build clients that can leverage text messaging without having to have a mobile device behind them.
In order to send and receive text messages, Outlook needs a service that conforms to the Office Mobile Service (OMS) guidelines. Building a .NET service that conform to these guidelines is made easy by using a standard ASMX Web Service and the Twilio .NET Helper Library.
Sending Text Messages using Outlook
The OMS guidelines describe how to use a basic SOAP web service to expose a standard set of endpoints that Outlook will call in order discover service and user information and send text messages.
At a high level, there are four methods an OMS service needs to expose:
- string GetServiceInfo() – Returns information about the service
- string GetUserInfo(string xmsUser) – Retrieves information about a user
- string DeliverXms(string xmsData) – Sends one mobile message
- string DeliverXmsBatch(string packageXml) – Sends multiple mobile messages in a batch
As Outlook calls each method it will pass in XML data which your service can parse in order to determine who is sending the message, what the body of the message is, and who the message is being sent to. An example of what Outlook passes to the DeliverXms method is below:
<?xml version="1.0" encoding="utf-8"?>
<xmsData client="Microsoft Office Outlook 12.0" xmlns="http://schemas.microsoft.com/office/Outlook/2006/OMS">
<content contentType="text/plain" contentId="Att0.txt@AB1B43B2B0594564.B94EF7ABB12B49BA"
contentLocation="1.txt">(1/2)This is the first SMS message...</content>
<content contentType="text/plain" contentId="Att1.txt@AB1B43B2B0594564.B94EF7ABB12B49BA"
contentLocation="2.txt">(2/2)This is the second SMS message...</content>
Once you’ve set up your service, you can test it by configuring the service as a new Mobile Service account in Outlook. Choosing the Text Message (SMS) option in Outlook will kick off this configuration.
The configuration dialog has you enter the service URL and a username and password and then lets you test the service. Notice that the service provider URL uses and HTTPS address. The OMS guidelines specify that the service must be run using SSL, and Outlook always uses SSL to call the service.
If Outlook successfully connects to the service then you can start using to send text messages right from Outlook:
One very nice feature of Outlooks text message editor is that it automatically splits messages over 160 characters up into multiple text messages, which you see in the screen shot above.
Receiving Messages in Outlook
The OMS guidelines also include information on how to handle incoming text messages. As with creating the OMS service for sending messages, receiving messages is simple as well, especially when using Twilio.
Simply create an endpoint that Twilio can call when it receives a message. If you are using .NET, that endpoint can be and HTTP handler, an ASP.NET MVC Action method, or even a standard ASPX web page. The logic in that page can receive the message from Twilio, then forward it via email into Outlook.
In order for Outlook to know that the incoming email originated as an SMS message, it looks for certain headers in the mail message. These headers tell Outlook not only that the message source is a text message, but also include the information that Outlook needs in order to create a text message reply.
An Office Message Service Sample
In order to show a full sample on how to create a OMS service I have created the Twilio Office Message Service sample. The sample shows how to create the OMS service to send messages, handle incoming messages, and also includes a simple website that lets users provide their own Twilio credentials in order to use the service. You can grab the full source for the sample application from GitHub.