How to send an SMS in Windows Phone 7
This article explains how to send an SMS in a Windows Phone 7 application.
See Also
Article Metadata
Code Example
Tested with
Compatibility
Article
Introduction
This code example shows how to send an SMS in a Windows Phone 7 app. The code example uses the SmsComposeTask (a type of Launcher) to open the native device SMS editor and give the user an option to send the SMS or discard it.
Source code
First create a sample windows phone application. This is done by choosing File->NewProject->Windows Phone Application in the Visual Studio 2010 . In the application a text label (label displaying the message to enter the SMS text), text editor (to enter the body for SMS) and a button (on the click of which sms editor opens up) are added in the MainPage.xaml file as follows:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBox Height="92" HorizontalAlignment="Left" Margin="56,121,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="289" />
<TextBlock Height="52" HorizontalAlignment="Left" Margin="26,51,0,0" Name="textBlock1" Text="Please enter text for sms:" VerticalAlignment="Top" Width="256" />
<Button Content="Send SMS" Height="86" HorizontalAlignment="Left" Margin="96,276,0,0" Name="button1" VerticalAlignment="Top" Width="198" Click="button1_Click" />
</Grid>
With above code written in XAML, the page created will look like:
In the MainPage.xaml.cs, add the following code:
...
using Microsoft.Phone.Tasks;
namespace SmsSender
{
...
// function which gets called when 'Send SMS' button is clicked
string ismsboby;
private void button1_Click(object sender, RoutedEventArgs e)
{
ismsboby = textBox1.Text; // Fetch the text from textbox created in XAML
SmsComposeTask smsComposeTask = new SmsComposeTask();
smsComposeTask.To = "9012345566778"; // Mention here the phone number to whom the sms is to be sent
smsComposeTask.Body = ismsboby; // the string containing the sms body
smsComposeTask.Show(); // this will invoke the native sms edtior
}
}
}
As soon as 'Send SMS' button is clicked it opens up the native SMS application with body message & phone number filled which we passed from the code above.
Once the user clicks on "Send" Button on native SMS application, SMS will be sent.


Vineet.jain - About the Article
EDIT :Added the comment to a note in the beginning of the article.
Vineetvineet.jain 20:34, 20 January 2012 (EET)
Hamishwillee - Useful - some suggestions
Hi Vineet
I've subedited this slightly and added more categories. The main advice I have for you on creating "pure" Windows Phone articles is that if there is a really good example on MSDN then there isn't all that much point in creating an article which duplicates it.
If you do, then it is essential that you to always add links to the reference documentation (I have done this in the SeeAlso and introduction above). This makes the information easy for the user to access official docs, and means that if the official docs get updated then its still accessible.
IMO what saves this article and makes it worthwhile is that it has the note explaining clearly that you can't embed SMS sending as part of your app (ie you must use the launcher) which helps Qt developers. Also this has a buildable examples, and that makes testing the code easier.
You could improve this further by having a more comparative app which shows porting your SMS sending app from Qt to WP or visa versa - thereby concentrating even more on the bits that help people navigate between Nokia platforms. Let me know if you need/want help with that.
HamishRegards
hamishwillee 08:55, 1 May 2012 (EEST)