Blue Theme Orange Theme Green Theme Red Theme
 
ASP.Net 4 Hosting is here
Home | Forums | Videos | Photos | Blogs | Beginners
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » Visual Basic 2005 » Send Text Message to Cell Phones from a VB.NET Application

Send Text Message to Cell Phones from a VB.NET Application


This article describes a simple way to send text messages to a cellular phone from within a VB.NET desktop application. The source code provided includes a relatively good list of carriers to simplify the task of connecting with a cell phone and the task itself is really no more difficult than sending an email message through a desktop or web based application.

Author Rank:
Total page views :  71344
Total downloads :  2714
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
SMS2Cell.zip
 
Become a Sponsor

Introduction:

This article describes a simple way to send text messages to a cellular phone from within a VB.NET  desktop application.  The source code provided includes a relatively good list of carriers to simplify the task of connecting with a cell phone and the task itself is really no more difficult than sending an email message through a desktop or web based application.

Getting Started:

In order to begin, unzip the downloaded files and open the project provided.  Within the project you will find one main class:  frmMain.vb.  The main form is a windows application form and it contains a few controls necessary to capture the fields needed to properly form the message.  These fields include:

  • Recipient's Phone Number:  Captures the recipient's cellular telephone number (10 digit)
  • Recipient's Carrier:  Captures the recipient's carrier.
  • Sender's email address:  Captures the sender's email address.
  • Sender's email server:  Captures the name of the sender's email server 
  • Message Subject Line:  Captures the message's title or subject
  • Message Body:  Captures the sender's message content.

The application is simple but could easily be improved by validating each of the required fields through the use of regular expressions or by at least validating that the text associated with each of the text boxes is not an empty string.  To maintain the simplicity of the project, little in the way of error handling has been included.

The following figure (Figure 1) shows a properly configured collection of input fields in use:

Figure 1: The Demonstration Application in Use

A quick review of the code will reveal that there is little going on there.  The following imports were added to the top of the class:

Imports System

Imports System.Net.Mail

The System.Net.Mail import brings in the support necessary to transmit the messages generated using the application.  Following the imports and the class declaration, there is a declarations region identified and within that region is a collection of private member variables; these private member variables are created in order to supply each of the required elements of the message.

#Region "Declarations"

 

' message elements

Private mMailServer As String

Private mTo As String

Private mFrom As String

Private mMsg As String

Private mSubject As String

 

#End Region

At this point, the only thing left to do in code is to  write the following  three methods:

#Region "Methods" 

 

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MyBase.Load

 

        ' set up the carriers list - this is a fair list, you may wish to

        ' research the topic and add others, it took a while to generate this

        ' list...

        cboCarrier.Items.Add("@itelemigcelular.com.br")

        cboCarrier.Items.Add("@message.alltel.com")

        cboCarrier.Items.Add("@message.pioneerenidcellular.com")

        cboCarrier.Items.Add("@messaging.cellone-sf.com")

        cboCarrier.Items.Add("@messaging.centurytel.net")

        cboCarrier.Items.Add("@messaging.sprintpcs.com")

        cboCarrier.Items.Add("@mobile.att.net")

        cboCarrier.Items.Add("@mobile.cell1se.com")

        cboCarrier.Items.Add("@mobile.celloneusa.com")

        cboCarrier.Items.Add("@mobile.dobson.net")

        cboCarrier.Items.Add("@mobile.mycingular.com")

        cboCarrier.Items.Add("@mobile.mycingular.net")

        cboCarrier.Items.Add("@mobile.surewest.com")

        cboCarrier.Items.Add("@msg.acsalaska.com")

        cboCarrier.Items.Add("@msg.clearnet.com")

        cboCarrier.Items.Add("@msg.mactel.com")

        cboCarrier.Items.Add("@msg.myvzw.com")

        cboCarrier.Items.Add("@msg.telus.com")

        cboCarrier.Items.Add("@mycellular.com")

        cboCarrier.Items.Add("@mycingular.com")

        cboCarrier.Items.Add("@mycingular.net")

        cboCarrier.Items.Add("@mycingular.textmsg.com")

        cboCarrier.Items.Add("@o2.net.br")

        cboCarrier.Items.Add("@ondefor.com")

        cboCarrier.Items.Add("@pcs.rogers.com")

        cboCarrier.Items.Add("@personal-net.com.ar")

        cboCarrier.Items.Add("@personal.net.py")

        cboCarrier.Items.Add("@portafree.com")

        cboCarrier.Items.Add("@qwest.com")

        cboCarrier.Items.Add("@qwestmp.com")

        cboCarrier.Items.Add("@sbcemail.com")

        cboCarrier.Items.Add("@sms.bluecell.com")

        cboCarrier.Items.Add("@sms.cwjamaica.com")

        cboCarrier.Items.Add("@sms.edgewireless.com")

        cboCarrier.Items.Add("@sms.hickorytech.com")

        cboCarrier.Items.Add("@sms.net.nz")

        cboCarrier.Items.Add("@sms.pscel.com")

        cboCarrier.Items.Add("@smsc.vzpacifica.net")

        cboCarrier.Items.Add("@speedmemo.com")

        cboCarrier.Items.Add("@suncom1.com")

        cboCarrier.Items.Add("@sungram.com")

        cboCarrier.Items.Add("@telesurf.com.py")

        cboCarrier.Items.Add("@teletexto.rcp.net.pe")

        cboCarrier.Items.Add("@text.houstoncellular.net")

        cboCarrier.Items.Add("@text.telus.com")

        cboCarrier.Items.Add("@timnet.com")

        cboCarrier.Items.Add("@timnet.com.br")

        cboCarrier.Items.Add("@tms.suncom.com")

        cboCarrier.Items.Add("@tmomail.net")

        cboCarrier.Items.Add("@tsttmobile.co.tt")

        cboCarrier.Items.Add("@txt.bellmobility.ca")

        cboCarrier.Items.Add("@typetalk.ruralcellular.com")

        cboCarrier.Items.Add("@unistar.unifon.com.ar")

        cboCarrier.Items.Add("@uscc.textmsg.com")

        cboCarrier.Items.Add("@voicestream.net")

        cboCarrier.Items.Add("@vtext.com")

        cboCarrier.Items.Add("@wireless.bellsouth.com")

 

    End Sub 

 

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

 

' Collect user input from the form and stow content into

' the objects member variables

 

        mTo = Trim(txtPhoneNumber.Text) &

  Trim(cboCarrier.SelectedItem.ToString())

        mFrom = Trim(txtSender.Text)

        mSubject = Trim(txtSubject.Text)

        mMailServer = Trim(txtMailServer.Text)

        mMsg = Trim(txtMessage.Text)

 

' Within a try catch, format and send the message to

' the recipient.  Catch and handle any errors.

        Try

 

            Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg)

            Dim mySmtpClient As New SmtpClient(mMailServer)

            mySmtpClient.UseDefaultCredentials = True

            mySmtpClient.Send(message)

 

            MessageBox.Show("The mail message has been sent to " &

message.To.ToString(), "Mail", MessageBoxButtons.OK,

MessageBoxIcon.Information)

 

        Catch ex As FormatException

 

            MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,

MessageBoxIcon.Error)

 

        Catch ex As SmtpException

 

            MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,

MessageBoxIcon.Error)

 

        Catch ex As Exception

 

            MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,

MessageBoxIcon.Error)

 

        End Try

 

    End Sub 

 

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles btnExit.Click

           

' Upon user's request, close the application

        Application.Exit()

 

    End Sub 

#End Region

At this point, the application should be complete you may wish to build the solution and test it.  Even though this example was intended to be simple, the overall concept may be used within an application to do some seemingly complex jobs.  For example, if you were tasked with writing an application that monitored some sort of trend information such as a daily stock price, and were to alert a group of end users whenever the stock price exceeded some predetermined, agreed upon value, you could do something such as looping through a collection of users subscribing to the stock price monitoring service and direct a text message to each of these users indicating that the watched stock had surpassed the threshold value. 

Also please note that, whilst it does cost you a dime to send a message to a cell phone in this manner, it may well cost the recipient something to receive it.  Bearing that in mind, as you test your version of the code, be mindful of an expenses you may be generating for yourself (if, for example, you are sending messages to yourself) or another person.


Login to add your contents and source code to this article
 About the author
 
Scott Lysle
Freelance software developer residing in Alabama. Bachelors, Masters Degrees from Wichita State University. I spent the first half of my career working on aircraft controls and displays and in that time I worked on the cockpits for the OH-58 AHIP, the AH-1W, the V-22, the F-22, the C-130J, the C-5 AMP, AWACS, JPATS, and a few others. Since 1997 I have been largely involved with Windows and web development, GIS application development, consumer electronics development (embedded linux/java), but still sometimes work on aircraft and military projects, the most recent of which was the presidential transport helicopter. I tend to work primarily with C/C++, Java, VB, and C#.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
SQL and .NET performance profiling in one place
Investigate SQL and .NET code side-by-side with ANTS Performance Profiler 6, so you can see which is causing the problem without switching tools.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
60 FREE UI Controls from DevExpress
Register for your FREE copy on over 60 free presentation controls from DevExpress - Absolutely Free-of-Charge without any royalties or distribution costs. Visit Devexpress.com/60 today. Free controls include advanced lists box, dropdown calendar, rich text edit, spin edit, tab control and so much more!

DevExpress engineers feature rich presentation controls and reporting tools for WinForms, ASP.NET, WPF, and Silverlight. Our technologies help you build your best, see complex software with greater clarity and deliver compelling business solutions for Windows and the web in the shortest possible time.
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or application via a range of API's. Learn More about our API connections.
Free access to .NET Memory Management video
Everything you need to know about Garbage Collection, Temporary Objects, Fragmentation, Finalization and common causes of memory leaks in .NET. Watch the video here.
Microsoft Visual Studio 2010
Visualize your workspace with new multiple monitor support, powerful Web development, new SharePoint support with tons of templates and Web parts, and more accurate targeting of any version of the .NET Framework. Get set to unleash your creativity.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Read the Top 10 Books for Microsoft Developers, 15 Days FREE
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
Try Safari Books Online - 15 Days FREE + 15% Off for 1 Year
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Chart
Become a Sponsor
 Comments
Can we get current location of the cell with some modifications in this code? If yes? Please tell me how can I achive this? by Mahesh On August 30, 2006
Hi, I am writing a desktop application in VB.Net and I want to get current location of the specific cell phone, so can we get current location of the cell phone with some modifications in this code? If yes? Please tell me how can I achive this? I am badly stucked up at this point. Please help me. Thanks in advance. Mahesh
Reply | Email | Delete | Modify | 
Re: Can we get current location of the cell with some modifications in this code? If yes? Please tell me how can I achive this? by Scott On September 3, 2006

Well, it is possible to get the current location of a cell phone but it would be a little more than a modification to this code.  I presume that you wish to plot the position of the phone on a map or something to that effect.  There is a project that I have seen that uses Microsoft's location web service in conjunction with Microsoft MapPoint in order to display the current position of a cell phone within a GIS based construct.

Take a look at this blog; there is some mention of it there but I do know there is an application with the source code provided floating around somewhere (if I find it I will let you know):

http://blogs.msdn.com/cthota/archive/2004/02/22/78004.aspx

In this blog, the author mentions using the phone to find out where he is (like what is my present position on the map); in the other application, the intent was to show you where a phone is (not yours specifically but any phone).  Of course one could think of many interesting applications that could be built around that functionality.

Thanks for the comment!

Scott

Reply | Email | Delete | Modify | 
Code about SMS to Cell with VB Net by Windarto On September 4, 2006

Hi, I'm Windarto

I'm new in VB Net.

I have problem when i'm trying to implement your code at my VB Net. Base on your code, you write on the Top of  Code is Import System and Imports System.Net.Mail, but when I type Import System.Net, no methods or namespace   MAIL, so when i do compile, i got some error like this Type 'mailMessage' is not Defined, Type 'smtpClient' is not defined, and Type 'smtpException' is not defined. So what I have to do, Thanks.

Regard

Windarto

Reply | Email | Delete | Modify | 
Re: Code about SMS to Cell with VB Net by Scott On September 29, 2006

Windarto:

This is a 2005 project and System.Net.Mail is new to 2005; are you coding in 2003 or 2005?

 

Best Regards,

Scott Lysle

Reply | Email | Delete | Modify | 
not able to import the namespace system.net.mail by Sridhar On December 28, 2006

hi scott,

iam using vs.net 2oo3 and framework 2.0 and in my application i was not able to import the namespace system.net.mail

i dont know whether it is applicable in vs.net 2005 only.

is it possible in vs.net 2003?

pl help me on this. its very urgent

thanks in advance

Reply | Email | Delete | Modify | 
Re: not able to import the namespace system.net.mail by Scott On December 28, 2006

If you want to develop against the 2.0 framework using the Visual Studio IDE you will need Visual Studio 2005; if you don't want to buy the 2005 IDE you can use any editor along with the SDK or you can use one of the limited but free express editions of the IDE.

Reply | Email | Delete | Modify | 
Sending sms using vb.net by Thosanjith On January 1, 2008
Can i use the above code to send sms with vb(2003)
Reply | Email | Delete | Modify | 
Re: Sending sms using vb.net by Scott On January 2, 2008

Send me an email message with your email address and I will send you a similar project written specifically for 2003.

Scott

Reply | Email | Delete | Modify | 
Re: Re: Sending sms using vb.net by James On March 16, 2008
is there anywhere I Can just get the VB Project file for 06? if you could send me something Id really appreciate it!.. JamesMaltby86@hotmail.com
Reply | Email | Delete | Modify | 
hi by saran On March 4, 2008
plz send me the project code for sending sms to mble for asp.net1.0 plz plz send me soon...... already i tk a project from this site. bt it shows too many errors.
Reply | Email | Delete | Modify | 
getting current gold rate from internet into desktop application by Ershad On March 10, 2008
i have developed one desktop application for jewellery shop now in that i want to get current rate of gold from internet. Please give any sollution for this if u guys know
Reply | Email | Delete | Modify | 
Re: getting current gold rate from internet into desktop application by Scott On March 11, 2008
You could look at the Xignite web services; I believe they have a web service that provides gold rates.
Reply | Email | Delete | Modify | 
problem by salman On August 15, 2008
hi i am very new to vb.net. tell me how can i learn vb.netand network programming from the grass root level.also tell me name of some of the good and lucid books for the same purpose.i am very fond of vb.net and network programming.but i do not have the resources to learn them
Reply | Email | Delete | Modify | 
help me scott by salman On August 15, 2008
hi scott i am from india. i am very new to the concept of programming itself.i started learning vb.net outof sheer curiosity.But now i am very fond of it.i want to learn it in depth. i do not have the resources to learn it.i want to learn vb.net and network programming in vb.net .please tell me any links and the names of the books that teach vb.net and network and internet programming in vb.net from the grassroot level
Reply | Email | Delete | Modify | 
i have a problem by Tariq On August 19, 2008
I have a problem with this code. I install vb.net 2003 and the code is in vs 2005 therefore the when I run the program an error occurs that is 'Namespace or type Mail for the System.Net.Mail not found'
Reply | Email | Delete | Modify | 
Problem Receiving SMS by Daniel On October 14, 2008
Hi there I use the following code (below) and get a confirmation message that the message was sent, however I have not yet received a text message on my mobile Here is the code I am using, . . I placed it in a module and called it in the form_load event (just on a trial basis) Many Thanks daÑÏ£L ----------------------- Imports System.Net.Mail Module Send_SMS_Module #Region "Declarations" ' message elements Private mMailServer As String Private mTo As String Private mFrom As String Private mMsg As String Private mSubject As String #End Region Public Sub SendText() ' Collect user input from the form and stow content into ' the objects member variables mTo = Trim("273301107") & _ Trim("@sms.net.nz") mFrom = Trim("dtibbotts@xtra.co.nz") mSubject = Trim("Hello") mMailServer = Trim("smtp.xtra.co.nz") mMsg = Trim("Text Message") ' Within a try catch, format and send the message to ' the recipient. Catch and handle any errors. Try Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg) Dim mySmtpClient As New SmtpClient(mMailServer) mySmtpClient.UseDefaultCredentials = True mySmtpClient.Send(message) MessageBox.Show("The mail message has been sent to " & _ message.To.ToString(), "Mail", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information) Catch ex As FormatException MessageBox.Show(ex.StackTrace, ex.Message, _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) Catch ex As SmtpException MessageBox.Show(ex.StackTrace, ex.Message, _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) Catch ex As Exception MessageBox.Show(ex.StackTrace, ex.Message, _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) End Try End Sub End Module
Reply | Email | Delete | Modify | 
Re: Problem Receiving SMS by Scott On October 15, 2008

Daniel:

Let's rule out the prospect of a bad sms address first.  If you would, send a regular email message to your phone using the same address and see if it goes through.

You can write me at scottlysle@cableone.net.

Scott

Reply | Email | Delete | Modify | 
recieve by mikias On December 11, 2009
how is it possible to recieve messages?

Reply | Email | Delete | Modify | 
Error while sendig sms by Dilip On January 24, 2010
Can you explain Recipient's Cellular Carrier and Sender's Mail Server ? When I try to send message it gives error as,
Failure sending mail.
Reply | Email | Delete | Modify | 
about sms2cell by krunal On February 22, 2010
this code does'nt works explain me why
Reply | Email | Delete | Modify | 
I want to know what is cellular carrier, what is sender's mail server by Mohamad On April 2, 2010
please reply me
Reply | Email | Delete | Modify | 
replica handbags by watches On July 11, 2010
replica handbags can give you that unique recognition in the society. These lv have become even more popular due to their outstanding looks and shine. The designs of the louis vuitton handbags make them the most popular brands of designer handbags. The louis vuitton bags are available in a variety of colors, designs and styles.
Reply | Email | Delete | Modify | 
viagra by watches On July 11, 2010
With the usage of Viagra for a drug cocktail restores virility because the prescription Cheap Cialis main biological action is to increase the nitric oxide production needed to encourage blood flow to the penis. The result is that a lot of young guys-and more than a few in their 30s, 40s and beyond-are suddenly more able to have sex when Viagra UK is least advisabl
Reply | Email | Delete | Modify | 
it throws an exception and shows error by maggie On July 23, 2010
error meaasge...
The SMTP server requires secure connection or the client was not authenticated...

and it also throws an Exception...
please help me
Reply | Email | Delete | Modify | 
ASP.Net 4 Hosting is here
 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2010.8.14
 © 2010  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.