Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
dear sir,
please help me i am makeing a desktop base application . in which i want to send sms to any mobile through internet service , and i have no idea how to code it.plz help me
thanks in advance.
Posted 21-Apr-13 1:57am
Comments
ThePhantomUpvoter at 21-Apr-13 7:58am
   
Ask your provider. They should be providing you sample code on using their service.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello, I use this library made by me, I hope this can help you, anyway if you have any problema or doubt about the code you can report to me,
 
So this is the code:
 
Imports System.IO.Ports
Imports System.IO.Ports.SerialPort
Imports System.Threading
 
Public Class smsclass
 

    Private WithEvents Serie As New SerialPort
    Private ReadThread As Thread
 
#Region "PROPIEDADES"
 
    Private CONTSMS As Boolean      '// Receives ">" that means that you have to write the body of the SMS
    Private ENDSMS As Boolean       '// Receive "+CMGS" that means that the SMS has been succesfully sent
    Private ERRORSMS As Boolean     '// It becomes true when an error occurred

#End Region
 
#Region "EVENTS"
 
    Public Event DataReceived(ByVal Message As String)  'Data received from the Serial port
    Public Event SMSSended(ByVal NumTelefono As String, ByVal Content As String, ByVal Id As String) 'SMS has been succesfully sent
    Public Event SMSError(ByVal Message As String)  'There was an error sending the SMS

#End Region
 
#Region "PROPERTIES"
 
    'Check the Serial Port Status

    Public ReadOnly Property IsOpen() As Boolean
        Get
            If Serie.IsOpen = True Then
                IsOpen = True
            Else
                IsOpen = False
            End If
        End Get
    End Property
#End Region
 

#Region "PUBLIC METHODS"
 
    'Public Method for Open the serial Port

    Public Sub Open(ByVal PortName As String, ByVal Speed As String)
 
        If IsOpen = False Then
 
            'Serial Port configuration
            Serie.PortName = PortName
            Serie.BaudRate = Speed
            Serie.DataBits = 8
            Serie.Parity = IO.Ports.Parity.None
            Serie.Handshake = IO.Ports.Handshake.RequestToSend
 
            Serie.RtsEnable = True
            Serie.DtrEnable = True
 
            ReadThread = New Thread(AddressOf Read)
 
            'Open the Serial Port and Start thread to read the port serial incoming data

            Try
                Serie.Open()
                ReadThread.Start()
            Catch ex As Exception
 
            End Try
 
        Else
 
        End If
 
    End Sub
 
    'Method to close serial port

    Public Sub Close()
 
        If IsOpen = True Then
            Serie.Close()
        End If
        ReadThread.Abort()
    End Sub
 
    'Method to Send a SMS

    Public Sub MandarSMS(ByVal ThelephoneNumber As String, ByVal Content As String, ByVal Id As String)
 
        '// States of the SMS progres to the initial value
        CONTSMS = False
        ENDSMS = False
        ERRORSMS = False
 
        If IsOpen = True Then
            Serie.WriteLine("AT+CMGS=" & ThelephoneNumber & vbCr)    '// Destinatario

            While CONTSMS = False
                System.Threading.Thread.Sleep(30)
            End While
 
            If (CONTSMS = True) Then
 
                Serie.WriteLine(Content & vbCrLf & Chr(26))  '// SMS CONTENT

            End If
 
            While (ENDSMS = False)
                System.Threading.Thread.Sleep(30)
 
                'THE MESSAGE COULD NOT BE DELIVERED
                If ERRORSMS = True Then
 
                    RaiseEvent SMSError(ThelephoneNumber) 'SMS ERROR
                    Exit While
 
                End If
            End While
 
            If ENDSMS = True Then
                RaiseEvent SMSSended(ThelephoneNumber, Content, Id) 'SMS WAS SENT
            End If
 
            ' Restart SMS status vars
            ENDSMS = False
            CONTSMS = False
            ERRORSMS = False
 
        End If
 
        System.Threading.Thread.Sleep(1000)
 
    End Sub
 
#End Region
 

#Region "PRIVATE METHODS"
    'Leer Puerto Serie

    Private Sub Read()
        Dim Incoming As String = Nothing
        While Serie.IsOpen = True
            If (Serie.BytesToRead <> 0) And (IsOpen = True) Then
                While Serie.BytesToRead <> 0
 
                    System.Threading.Thread.Sleep(30)
 
                    Incoming = Serie.ReadExisting()
 
                    If Incoming.Contains(">") Then
                        CONTSMS = True
                    End If
 
                    If Incoming.Contains("+CMGS:") Then
                        ENDSMS = True
                    End If
 
                    If Incoming.Contains("ERROR") Then
                        ERRORSMS = True
                    End If
 
                    RaiseEvent DataReceived(Incoming)
                End While
 
            End If
 
            System.Threading.Thread.Sleep(300)
        End While
    End Sub
#End Region
 

End Class
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 Afzaal Ahmad Zeeshan 132
2 ProgramFOX 130
3 Maciej Los 115
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 23 Nov 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100