Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
sir, iam using asp.net3.5 with c#.net

i want to send sms to mobile how shall i do it can you help me please
Posted

Without SMS gateway you can't do it. here is link[^] to help you.
 
Share this answer
 
Comments
Rajesh Anuhya 31-Dec-11 6:37am    
very cool prasad, have my +5
Monjurul Habib 8-Apr-12 12:20pm    
5!
go through this video

here[^]
 
Share this answer
 
Comments
Monjurul Habib 8-Apr-12 12:21pm    
5!
 
Share this answer
 
Comments
Monjurul Habib 8-Apr-12 12:20pm    
5!
C#
public class SendSms
{

    static AutoResetEvent readNow = new AutoResetEvent(false);
    static SerialPort port;

    private static string ExecuteCommand(string command, int timeout)
    {
        byte[] replyData = new byte[80];
        port.DiscardInBuffer();
        port.DiscardOutBuffer();
        readNow.Reset();
        port.Write(command + "\r");
        port.Read(replyData, 0, replyData.Length);
        return ASCIIEncoding.ASCII.GetString(replyData);
    }


    private static SerialPort EstablishConnection(string portName)
    {
        SerialPort port = new SerialPort();
        if (portName.ToUpper().StartsWith("COM") == false) portName = "COM" + portName;
        port.PortName = portName;
        port.BaudRate = 9600;
        port.DataBits = 8;
        port.StopBits = StopBits.One;
        port.Parity = Parity.None;
        //port.ReadTimeout = 2000;
        //port.WriteTimeout = 5000;
        port.Encoding = Encoding.GetEncoding("iso-8859-1");
        port.DataReceived += new SerialDataReceivedEventHandler(DataReceived);
        port.Open();
        port.DtrEnable = true;
        port.RtsEnable = true;
        return port;
    }

    private static void DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        if (e.EventType == SerialData.Chars)
            readNow.Set();
    }

    public static bool Send(string Mobile, string Message, string portname)
    {
        try
        {
            port = EstablishConnection(portname);
        }
        catch
        {
            return false;
        }
        string recievedData = ExecuteCommand("AT", 300);
        recievedData = ExecuteCommand("AT+CMGF=1", 300);
        String command = "AT+CMGS=\"" + Mobile + "\"";
        recievedData = ExecuteCommand(command, 300);
        string message = Message;
        command = message + char.ConvertFromUtf32(26) + "\r";
        recievedData = ExecuteCommand(command, 300);
        if (recievedData.EndsWith("\r\nOK\r\n")) recievedData = "Message sent successfully";
        if (recievedData.Contains("ERROR"))
        {
            port.Close();
            return false;
        }
        else
        {
            port.Close();
            return true;
        }
    }
}


Take this as class file. before launching this connect the mobile to the computer, and note the port number of the mobile connected to system and give that to portNumber vairiable.
 
Share this answer
 
Comments
Rajesh Anuhya 31-Dec-11 6:36am    
How this is can work in Asp.net page ???
Suraj S Koneri 31-Dec-11 6:40am    
wherever the need of sending sms, there call Send() function with mobile number, message, port number from the asp page..
foxup.net 26-Sep-12 14:34pm    
Worked like a charm. Thank you!
Member 11345989 14-Mar-15 10:24am    
This code is not working on my laptop. I enter COM3 and i have attached the mobile with COM3 port. But it does not go into the condition where it checks the received message ending.

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