Answered Sending sms through ASP.NET web page

  • Wednesday, October 19, 2011 9:00 AM
     
     
    I'm developing a web page using ASP.NET with C# and SQLServer. In this i need to send sms to mobiles through my web page. I need some suggestions to get this work done.

All Replies

  • Wednesday, October 19, 2011 9:31 AM
     
     

    i think u need a provider.like u can use skype com etc...to sent the sms

    i think this is the way.

     

    hope will helping you~

  • Wednesday, October 19, 2011 9:34 AM
     
     

    There're many options available. You can host the function using your own SMS gateway, web based SMS data services from your ISP or 3rd party vendors, or in certain regions, there're even free SMS webservice provider that you can use.

    The number of options you can actually use depends on where your application's target audiences lives.


    • Edited by cheong00 Thursday, October 20, 2011 8:13 AM
    •  
  • Thursday, October 20, 2011 8:07 AM
    Moderator
     
     Proposed Answer

    Hi Aruncode,
    Welcome to the MSDN forum!

    You can contact more experts on ASP.NET at: forums.asp.net where you can get more responses to ASP.NET issues.

    Home › ASP.NET Forums › General ASP.NET › Getting Started

    In the meantime, please take a look at the following thread as a reference:

    sms code

    http://forums.asp.net/t/1717569.aspx/1?sms+code

    Thank you for your understanding and have a nice day!


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed As Answer by BoovendanM Thursday, October 20, 2011 8:37 AM
    •  
  • Friday, October 21, 2011 3:49 PM
     
     
    In windows 7 there is no hyperterminal. How can i send sms using AT commands in windows 7? And i want to know what is alternative for hyperterminal in windows 7?
  • Monday, October 24, 2011 1:36 AM
     
     

    In your application, you'll just have to use System.IO.Ports.SerialPort class to do the serial communication part.

    If you try to test yourself, I can reassure you that HyperTerminal in WinXP and Win2k still works in Win7. You just have to extract the hypertrm.EXE and htrn_jis.dll.DLL from the install disk and place them in the same folder for it to work.

    If you don't have WinXP/Win2k disk readily available, you can try to use PuTTY (The configuration. the settings are at the final item on the configuration screen.)


    • Edited by cheong00 Monday, October 24, 2011 1:40 AM
    • Edited by cheong00 Monday, October 24, 2011 1:40 AM
    •  
  • Tuesday, October 25, 2011 8:35 AM
     
     Answered

    Below code works very well.. If u have further doubts post in this thread..

    use this namespace at the begining System.IO.Ports;

    Inside class or any of ur convenient event function write the below code..

          SerialPort SMSPort = new SerialPort();
          SMSPort.PortName = "COM9"; // this may vary for u.
          SMSPort.BaudRate = 9600;
          SMSPort.Parity = Parity.None;
          SMSPort.DataBits = 8;
          SMSPort.StopBits = StopBits.One;
          SMSPort.Handshake = Handshake.RequestToSend;
          SMSPort.DtrEnable = true;
          SMSPort.RtsEnable = true;
          SMSPort.Open();

     


          SMSPort.WriteLine("AT\r");
          SMSPort.WriteLine("AT+CMGF=1\r");
          SMSPort.WriteLine("AT+CMGS=\"9789305798\"\r");
          SMSPort.WriteLine("MSG from C# with slash r and slashes for quotes." + '\x001a');

     

     

          // This code also works well!
          SMSPort.WriteLine("AT" + char.ConvertFromUtf32(13));
          SMSPort.WriteLine("AT+CMGF=1" + char.ConvertFromUtf32(13));
          SMSPort.WriteLine("AT+CMGS=" + char.ConvertFromUtf32(34) + "9789305798" + char.ConvertFromUtf32(34) + char.ConvertFromUtf32(13));
          SMSPort.WriteLine("MSG from C# without slash r and slashes for quotes."+char.ConvertFromUtf32(26));

     

    Thank u..


    • Edited by Aruncode47 Tuesday, October 25, 2011 8:37 AM
    • Marked As Answer by Aruncode47 Tuesday, October 25, 2011 8:38 AM
    •  
  • Tuesday, October 25, 2011 9:02 AM
    Moderator
     
     

    Congratulations that you have figured out the problem!

    Thank you for sharing the solution with us and have a nice day!

     


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Thursday, October 27, 2011 4:04 PM
     
     

    It is hard to find the solution for sending SMS to multiple recipients.

    Guys i need ur suggestions..

    I've googled about it and learned something. Please tell me the step by step procedure.

  • Tuesday, November 01, 2011 4:02 AM
    Moderator
     
     

    Thanks all for your fast help.

    Hi Aruncode,

    Welcome to MSDN Forum.

     

    1) The SerialPort class cannot be used to communicate with multiple ports at one time.

    Check this article for detailed instruction: Serial COM Port Communication in .Net

    http://www.innovatic.dk/knowledg/SerialCOM/SerialCOM.htm

    http://www.c-sharpcorner.com/uploadfile/eclipsed4utoo/serialportcommunication12082008111137am/serialportcommunication.aspx

     

    2) To send SMS to multiple recipients, you can consider cheong00’s suggestion about other approaches.

    There're many options available. You can host the function using your own SMS gateway, web based SMS data services from your ISP or 3rd party vendors, or in certain regions, there're even free SMS webservice provider that you can use.

    Reference: How to send SMS to multiple recipients?

    http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/8c872e80-c26a-4f97-9c99-875e3eb1a5a4/

     

    3) By the way, maybe you feel interested in this FAQ: How do I implement Serial COM Port communication in .Net?

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/4ebccff7-baf6-4f2d-ae40-bb8733c2c805

    Code sample: Receive data from Serial Port and show on UI controls.

    Prerequisites: DragSerialPort1 and TextBox1 onto Form1.

    public class Form1

    { 

        private string inputData = "";

        public event IO.Ports.SerialDataReceivedEventHandler DataReceived;

       

    private void Form1_Load(object sender, System.EventArgs e)

    {

            // Set values for some properties

            SerialPort1.PortName = "COM1";

            SerialPort1.BaudRate = 9600;

            SerialPort1.Parity = IO.Ports.Parity.None;

            SerialPort1.DataBits = 8;

            SerialPort1.StopBits = IO.Ports.StopBits.One;

            SerialPort1.Handshake = IO.Ports.Handshake.None;

            SerialPort1.RtsEnable = true;

            SerialPort1.Open();

            // Writes data to the Serial Port output buffer

            if ((SerialPort1.IsOpen == true))

            {

                SerialPort1.Write("MicroCommand");

            }

        }

       

        //  Receive data from the Serial Port

    private void SerialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)

    {

            inputData = SerialPort1.ReadExisting;

            // or SerialPort1.ReadLine

    this.Invoke((MethodInvoker)delegate {DoUpdate();});

        }

       

        // Show received data on UI controls and do something

    public void DoUpdate()

    {

            TextBox1.Text = (TextBox1.Text + inputData);

        }

     

    private void Form1_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)

    {

            //  Close the Serial Port

            SerialPort1.Close();

        }

    }

     


    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Tuesday, November 01, 2011 6:01 AM
     
     

    Oops I think you have misread this. Aruncode has already gone past the phase to implement serial communication to builtin modem or SMS gateway (since both use AT code to work, I can't tell which is the approach he chosen to adapt)

    His problem is on specifying multiple recipients, much like when you finally success on connect to SMTP server to send mail, you can't find out how to send to multiple receipients at once.

    Brief search found it involves using +CMSS AT command instead of using CMGS, but I think he found that out already so I chosen not to comment.Since he had already implemented using CMGS way, it should be easy. The part didn't spell out is how to find out the index of storage for the SMS you just composed, for this part you'll just find out the sample for +CMGD command (section 24.3) to see it's the value be returned when the message is composed.


    • Edited by cheong00 Tuesday, November 01, 2011 6:03 AM
    • Edited by cheong00 Tuesday, November 01, 2011 6:10 AM
    • Edited by cheong00 Tuesday, November 01, 2011 6:51 AM
    •  
  • Tuesday, November 01, 2011 9:12 AM
    Moderator
     
     
    Thanks cheong00 for your good suggestions and great help. I'm very glad to read your posts.
    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Tuesday, November 01, 2011 12:59 PM
     
     

    Thanks cheong00 and Martin_Xie fro ur valuable suggestions.

    I've read the complete article in the developershome.com to know how to send SMS using Serial port.

    And i read the multiple recipient article also. My question is how to implement the AT+CMCW and CMSS command in my C# coding.

    I succeed with single recipient.

  • Wednesday, November 02, 2011 1:27 AM
     
     

    Well, you just need to change CMGS to CMGW, then read the response to get the index number, and proceed to send using the same index. The whole listing would be as the following:

    AT+CMGF=1<CR>
    Remote side returns: OK<CR><LF>
    AT+CPMS="ME","SM"<CR>
    Remote side returns: +CPMS: <some comma delimited numbers indicates used space and max space for storage specified><CR><CR>OK<CR><LF>
    AT+CSCA="Your SMS service centre number"<CR>
    Remote side returns: OK<CR><LF>
    AT+CMGW="1st number"<CR>Message content.<Ctrl+z>
    Remote side returns:
    +CMGW: index<CR><LF> or
    Remote side returns:
    +CMS ERROR: <Error code><CR><LF>
    AT+CMSS=index<CR>
    Remote side returns: OK<CR><LF>
    AT+CMSS=index, "2nd number"<CR>
    Remote side returns: OK<CR><LF>
    AT+CMSS=index, "3rd number"<CR>
    Remote side returns: OK<CR><LF>
    ... Repeat as many time as needed to send all the numbers with same content.
    AT+CMGD=index<CR>
    Remote side returns: OK<CR><LF>

    After you executes CMGW, be sure to call CMGD to delete the message in storage area or the index will be used up soon. For this reason, you'll want to put the code for this cleanup in a finally block.

    Since the data received does affect the message be sent in the next step, I think using the blocking SerialPort.ReadLine() shall be more appropiate. For this reason, remember to set the ReadTimeout value, and consider moving all the SMS message sending related code to a seperate thread.

    It should be helpful to create a small message parsing class to check if after reading the current message, it should keep reading (e.g. when reading lines while either OK or error message is expected, it should keep reading), proceed to next command, or just return because error is returned.

    EDIT: Corrected the extended commands must be end with <CR>, and the response code will be end with <CR><LF>
    EDIT2: Figure that maybe I should add the whole message sending block. Note that the CPMS and CSCA commands are not always required. Read the article for their meaning and decide whether you should use them or not.



    • Edited by cheong00 Wednesday, November 02, 2011 1:28 AM
    • Edited by cheong00 Wednesday, November 02, 2011 1:32 AM
    • Edited by cheong00 Wednesday, November 02, 2011 1:33 AM
    • Edited by cheong00 Wednesday, November 02, 2011 1:50 AM
    • Edited by cheong00 Wednesday, November 02, 2011 1:59 AM
    • Edited by cheong00 Wednesday, November 02, 2011 2:00 AM
    •