Click here to Skip to main content
15,792,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to develop a web application which sends messages to mobile phones via GSM modem programmatically.I tried using the GsmComm functions i am encountering Message Service Error 500.Is the way of approach is the same as normal c# form application or different.Please suggest the correct way.
Posted

1 solution

C#
public void SendSMS(string phoneNo, string message)
        {
            System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort("COM13", 115200, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            try
            {
                port.Open();
                port.Write("AT\r\n");
                System.Threading.Thread.Sleep(1000);
                port.WriteLine("AT+CMGF=1\r\n");
                System.Threading.Thread.Sleep(1000);
                //port.WriteLine("AT+CMGS=\"+60121212121\"\r\n");
                port.WriteLine("AT+CMGS=\"" + phoneNo + "\"\r\n");
                System.Threading.Thread.Sleep(1000);
                //port.WriteLine("Testing SMS\r\n" + '\x001a');
                port.WriteLine(message + "\r\n" + '\x001a');
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                port.Close();
            }
        }
 
Share this answer
 
Comments
Member 8301043 25-Feb-12 13:17pm    
Actually i implemented a c# windows application for sending sms via gsm modem without the help of AT commands and by using GsmComm.dll.Can the same dll can be used??

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