Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear All I Already Using a Code With At Command With Nokia Phone For Sending SMS by Using Data cable As Now A Day Smart Phone Have to all Person Then please any one help me or Guide me How To Send SMS By Android Phone

What I have tried:

public class CommSetting
    public static int Comm_Port=0;
    public static Int64 Comm_BaudRate=0;
    public static Int64 Comm_TimeOut=0;
    public static GsmCommMain comm;

    public CommSetting()
        // TODO: Add constructor logic here

GsmCommMain comm = new GsmCommMain(port, baudRate, timeout);
        while (!comm.IsConnected())
            Cursor.Current = Cursors.Default;
            if (MessageBox.Show(this, "No phone connected.",
               "Connection setup", MessageBoxButtons.RetryCancel,
                 MessageBoxIcon.Exclamation) == DialogResult.Cancel)
            Cursor.Current = Cursors.WaitCursor;

        // Close Comm port connection (Since it's just for testing
        // connection)
catch(Exception ex)
    MessageBox.Show(this, "Connection error: " + ex.Message,
    "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);

// display message if connection is a success.
MessageBox.Show(this, "Successfully connected to the phone.",
"Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information);

private void MessageReceived()
    Cursor.Current = Cursors.WaitCursor;
    string storage = GetMessageStorage();
    DecodedShortMessage[] messages = CommSetting.comm.ReadMessages
                   (PhoneMessageStatus.ReceivedUnread, storage);
    foreach(DecodedShortMessage message in messages)
         Output(string.Format("Message status = {0},
     Location =  {1}/{2}",
         message.Storage, message.Index));

    Output(string.Format("{0,9} messages read.",
Updated 12-Jan-20 7:29am


As per understand you are opening a comport of your Phone modem. and trying to communicate. I do see the comport configurations are incorrect because port 0 buadrate 0 is invalid.

I think you need to get some information about the how to communicate hardware with comport.

Second, when you are connect directly through the modem (not phone software). you need to use modem commands called AT commands[^]

I have worked on this almost 7 years back, I did not remember correctly command for sending SMS, But I am giving below example you can try it.

<SMS MEssage> 

Tip: before doing this in the C# code use and Terminal window ,I used hyperterminal ( not available after xp, but you can download exe from web). you can test this commands and everything is OK. Then start codeing in C#.

Good Luck
Share this answer
irfanansari 13-Nov-18 7:38am    
sir thanks a lot your response there are a lot of people but no one ready to help me
sir actually my question is that i have a smart phone amazon fire or Samsung any model i already connected it and i am able to access my smart phone by data-cable how can i send sms by using a or c# software i did very good practice by nokia keypad mobiles it is shows comport then i access it easily like Nokia 6680 ETC

Write this code in the top

Imports System.IO.Ports
Imports System.IO


Write this code in the public class of form:

Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String

Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.

And write this code in the button click event.

If SerialPort.IsOpen Then
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf

Dim message As String
message = MsgRichTextBox.Text

Catch ex As Exception
MsgBox("The modem with the port '" & SerialPort.PortName & "'is not plugged in!!" & vbcrlf & "Please plug the modem and try again.")
End Try

If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
MsgBox("Port '" & SerialPort.PortName & "' is not available!")
End If
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900