Sending sms to mobile phone in C#.net windows application with MTS modem












1















This is the code the message box showing ("message sent successfully"). But I didn't get the message to my phone that I used.



SerialPort sp = new SerialPort();
sp.PortName = "COM4";//choose your port wisely
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.Open();
sp.Write("AT+CMGS=";+91" + textBox1.Text + """ + Environment.NewLine);
Thread.Sleep(2000);
sp.Write(textBox2.Text + (char)26 + Environment.NewLine);
MessageBox.Show("Message sent successfully");









share|improve this question





























    1















    This is the code the message box showing ("message sent successfully"). But I didn't get the message to my phone that I used.



    SerialPort sp = new SerialPort();
    sp.PortName = "COM4";//choose your port wisely
    sp.BaudRate = 9600;
    sp.Parity = Parity.None;
    sp.Open();
    sp.Write("AT+CMGS=";+91" + textBox1.Text + """ + Environment.NewLine);
    Thread.Sleep(2000);
    sp.Write(textBox2.Text + (char)26 + Environment.NewLine);
    MessageBox.Show("Message sent successfully");









    share|improve this question



























      1












      1








      1


      1






      This is the code the message box showing ("message sent successfully"). But I didn't get the message to my phone that I used.



      SerialPort sp = new SerialPort();
      sp.PortName = "COM4";//choose your port wisely
      sp.BaudRate = 9600;
      sp.Parity = Parity.None;
      sp.Open();
      sp.Write("AT+CMGS=";+91" + textBox1.Text + """ + Environment.NewLine);
      Thread.Sleep(2000);
      sp.Write(textBox2.Text + (char)26 + Environment.NewLine);
      MessageBox.Show("Message sent successfully");









      share|improve this question
















      This is the code the message box showing ("message sent successfully"). But I didn't get the message to my phone that I used.



      SerialPort sp = new SerialPort();
      sp.PortName = "COM4";//choose your port wisely
      sp.BaudRate = 9600;
      sp.Parity = Parity.None;
      sp.Open();
      sp.Write("AT+CMGS=";+91" + textBox1.Text + """ + Environment.NewLine);
      Thread.Sleep(2000);
      sp.Write(textBox2.Text + (char)26 + Environment.NewLine);
      MessageBox.Show("Message sent successfully");






      c# windows






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 9:34









      Wai Ha Lee

      5,829123664




      5,829123664










      asked Jan 10 '14 at 19:53









      user3171896user3171896

      3114




      3114
























          3 Answers
          3






          active

          oldest

          votes


















          0














          this is my code and its worked for me 100% :



          private SerialPort _serialPort;
          public Form1()
          {
          InitializeComponent();
          }

          private void Form1_Load(object sender, EventArgs e)
          {

          }

          private void button1_Click(object sender, EventArgs e)
          {
          string number = textBox1.Text;
          string message = richTextBox1.Text;



          //Replace "COM8"withcorresponding port name
          _serialPort = new SerialPort("COM8", 115200);

          Thread.Sleep(100);

          _serialPort.Open();

          Thread.Sleep(100);

          _serialPort.Write("AT+CMGF=1r");

          Thread.Sleep(100);

          _serialPort.Write("AT+CMGS="" + number + ""rn");

          Thread.Sleep(100);

          _serialPort.Write(message + "x1A");

          Thread.Sleep(300);

          label1.Text = "Message sent !!";

          _serialPort.Close();
          }





          share|improve this answer
























          • Why are there so many Thread.Sleep(X); in there?

            – LenglBoy
            Oct 18 '17 at 10:57











          • Because your using AT&T code to communicate with a device , there should be a brake between every operation .

            – nassimlouchani
            Nov 8 '17 at 23:23



















          0














          This question bubbled up, so I thought it might be good to answer with an approach that is highly relevant today. As Farzan mentioned in a comment on his answer, there are service providers available that expose APIs which allow you to send SMS messages. This is even more relevant now as it has become somewhat rare to find landline telephones and even more rare to find a computer with a modem installed. Twilio is one of the available providers and has made sending an SMS trivial from a development perspective.



          // Twilio usings
          using Twilio;
          using Twilio.Rest.Api.V2010.Account;
          using Twilio.Types;

          const string accountSid = "your_account_sid"; // specific to your Twilio account
          const string authToken = "your_auth_token"; // specific to your Twilion account

          TwilioClient.Init(accountSid, authToken);

          // Send a new outgoing SMS by POSTing to the Messages resource
          MessageResource.Create(
          from: new PhoneNumber("555-867-5309"), // From number must be an SMS-enabled Twilio number
          to: new PhoneNumber(textBox1.Text),
          body: textBox2.Text); // Message content

          MessageBox.Show("Message sent successfully");


          Twilio is a subscription service, but they have a "pay as you go" plan that currently costs less than $.01 (US) per message.






          share|improve this answer































            -1














            Please try this code:



            private void Send()
            {
            SerialPort sp = new SerialPort();
            sp.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived);
            sp.PortName = "COM4";//choose your port wisely
            sp.BaudRate = 9600;
            sp.Parity = Parity.None;
            sp.Open();

            // Set the GSM modem to Text Mode
            sp.WriteLine("AT+CMGF=1"+Environment.NewLine);
            // Specifying mobile number
            sp.WriteLine(string.Format("AT+CMGS="+91{0}"{1}", textBox1.Text, Environment.NewLine));
            // Specifying sms body
            sp.WriteLine(textBox2.Text + (char)26 + Environment.NewLine);
            MessageBox.Show("Message sent successfully");
            }

            private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
            {
            SerialPort sp = (SerialPort)sender;
            string modemResult = sp.ReadExisting();
            this.yourTextBox.Text += modemResult;
            }


            Hope it helps






            share|improve this answer


























            • Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

              – user3171896
              Jan 11 '14 at 18:52











            • We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

              – Farzan
              Jan 13 '14 at 0:50











            • hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

              – amateur programmer
              Sep 8 '15 at 11:27











            • @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

              – Farzan
              Sep 13 '15 at 21:47













            • @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

              – amateur programmer
              Sep 14 '15 at 13:29











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21053274%2fsending-sms-to-mobile-phone-in-c-net-windows-application-with-mts-modem%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            this is my code and its worked for me 100% :



            private SerialPort _serialPort;
            public Form1()
            {
            InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void button1_Click(object sender, EventArgs e)
            {
            string number = textBox1.Text;
            string message = richTextBox1.Text;



            //Replace "COM8"withcorresponding port name
            _serialPort = new SerialPort("COM8", 115200);

            Thread.Sleep(100);

            _serialPort.Open();

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGF=1r");

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGS="" + number + ""rn");

            Thread.Sleep(100);

            _serialPort.Write(message + "x1A");

            Thread.Sleep(300);

            label1.Text = "Message sent !!";

            _serialPort.Close();
            }





            share|improve this answer
























            • Why are there so many Thread.Sleep(X); in there?

              – LenglBoy
              Oct 18 '17 at 10:57











            • Because your using AT&T code to communicate with a device , there should be a brake between every operation .

              – nassimlouchani
              Nov 8 '17 at 23:23
















            0














            this is my code and its worked for me 100% :



            private SerialPort _serialPort;
            public Form1()
            {
            InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void button1_Click(object sender, EventArgs e)
            {
            string number = textBox1.Text;
            string message = richTextBox1.Text;



            //Replace "COM8"withcorresponding port name
            _serialPort = new SerialPort("COM8", 115200);

            Thread.Sleep(100);

            _serialPort.Open();

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGF=1r");

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGS="" + number + ""rn");

            Thread.Sleep(100);

            _serialPort.Write(message + "x1A");

            Thread.Sleep(300);

            label1.Text = "Message sent !!";

            _serialPort.Close();
            }





            share|improve this answer
























            • Why are there so many Thread.Sleep(X); in there?

              – LenglBoy
              Oct 18 '17 at 10:57











            • Because your using AT&T code to communicate with a device , there should be a brake between every operation .

              – nassimlouchani
              Nov 8 '17 at 23:23














            0












            0








            0







            this is my code and its worked for me 100% :



            private SerialPort _serialPort;
            public Form1()
            {
            InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void button1_Click(object sender, EventArgs e)
            {
            string number = textBox1.Text;
            string message = richTextBox1.Text;



            //Replace "COM8"withcorresponding port name
            _serialPort = new SerialPort("COM8", 115200);

            Thread.Sleep(100);

            _serialPort.Open();

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGF=1r");

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGS="" + number + ""rn");

            Thread.Sleep(100);

            _serialPort.Write(message + "x1A");

            Thread.Sleep(300);

            label1.Text = "Message sent !!";

            _serialPort.Close();
            }





            share|improve this answer













            this is my code and its worked for me 100% :



            private SerialPort _serialPort;
            public Form1()
            {
            InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void button1_Click(object sender, EventArgs e)
            {
            string number = textBox1.Text;
            string message = richTextBox1.Text;



            //Replace "COM8"withcorresponding port name
            _serialPort = new SerialPort("COM8", 115200);

            Thread.Sleep(100);

            _serialPort.Open();

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGF=1r");

            Thread.Sleep(100);

            _serialPort.Write("AT+CMGS="" + number + ""rn");

            Thread.Sleep(100);

            _serialPort.Write(message + "x1A");

            Thread.Sleep(300);

            label1.Text = "Message sent !!";

            _serialPort.Close();
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 1 '14 at 18:41









            nassimlouchaninassimlouchani

            31438




            31438













            • Why are there so many Thread.Sleep(X); in there?

              – LenglBoy
              Oct 18 '17 at 10:57











            • Because your using AT&T code to communicate with a device , there should be a brake between every operation .

              – nassimlouchani
              Nov 8 '17 at 23:23



















            • Why are there so many Thread.Sleep(X); in there?

              – LenglBoy
              Oct 18 '17 at 10:57











            • Because your using AT&T code to communicate with a device , there should be a brake between every operation .

              – nassimlouchani
              Nov 8 '17 at 23:23

















            Why are there so many Thread.Sleep(X); in there?

            – LenglBoy
            Oct 18 '17 at 10:57





            Why are there so many Thread.Sleep(X); in there?

            – LenglBoy
            Oct 18 '17 at 10:57













            Because your using AT&T code to communicate with a device , there should be a brake between every operation .

            – nassimlouchani
            Nov 8 '17 at 23:23





            Because your using AT&T code to communicate with a device , there should be a brake between every operation .

            – nassimlouchani
            Nov 8 '17 at 23:23













            0














            This question bubbled up, so I thought it might be good to answer with an approach that is highly relevant today. As Farzan mentioned in a comment on his answer, there are service providers available that expose APIs which allow you to send SMS messages. This is even more relevant now as it has become somewhat rare to find landline telephones and even more rare to find a computer with a modem installed. Twilio is one of the available providers and has made sending an SMS trivial from a development perspective.



            // Twilio usings
            using Twilio;
            using Twilio.Rest.Api.V2010.Account;
            using Twilio.Types;

            const string accountSid = "your_account_sid"; // specific to your Twilio account
            const string authToken = "your_auth_token"; // specific to your Twilion account

            TwilioClient.Init(accountSid, authToken);

            // Send a new outgoing SMS by POSTing to the Messages resource
            MessageResource.Create(
            from: new PhoneNumber("555-867-5309"), // From number must be an SMS-enabled Twilio number
            to: new PhoneNumber(textBox1.Text),
            body: textBox2.Text); // Message content

            MessageBox.Show("Message sent successfully");


            Twilio is a subscription service, but they have a "pay as you go" plan that currently costs less than $.01 (US) per message.






            share|improve this answer




























              0














              This question bubbled up, so I thought it might be good to answer with an approach that is highly relevant today. As Farzan mentioned in a comment on his answer, there are service providers available that expose APIs which allow you to send SMS messages. This is even more relevant now as it has become somewhat rare to find landline telephones and even more rare to find a computer with a modem installed. Twilio is one of the available providers and has made sending an SMS trivial from a development perspective.



              // Twilio usings
              using Twilio;
              using Twilio.Rest.Api.V2010.Account;
              using Twilio.Types;

              const string accountSid = "your_account_sid"; // specific to your Twilio account
              const string authToken = "your_auth_token"; // specific to your Twilion account

              TwilioClient.Init(accountSid, authToken);

              // Send a new outgoing SMS by POSTing to the Messages resource
              MessageResource.Create(
              from: new PhoneNumber("555-867-5309"), // From number must be an SMS-enabled Twilio number
              to: new PhoneNumber(textBox1.Text),
              body: textBox2.Text); // Message content

              MessageBox.Show("Message sent successfully");


              Twilio is a subscription service, but they have a "pay as you go" plan that currently costs less than $.01 (US) per message.






              share|improve this answer


























                0












                0








                0







                This question bubbled up, so I thought it might be good to answer with an approach that is highly relevant today. As Farzan mentioned in a comment on his answer, there are service providers available that expose APIs which allow you to send SMS messages. This is even more relevant now as it has become somewhat rare to find landline telephones and even more rare to find a computer with a modem installed. Twilio is one of the available providers and has made sending an SMS trivial from a development perspective.



                // Twilio usings
                using Twilio;
                using Twilio.Rest.Api.V2010.Account;
                using Twilio.Types;

                const string accountSid = "your_account_sid"; // specific to your Twilio account
                const string authToken = "your_auth_token"; // specific to your Twilion account

                TwilioClient.Init(accountSid, authToken);

                // Send a new outgoing SMS by POSTing to the Messages resource
                MessageResource.Create(
                from: new PhoneNumber("555-867-5309"), // From number must be an SMS-enabled Twilio number
                to: new PhoneNumber(textBox1.Text),
                body: textBox2.Text); // Message content

                MessageBox.Show("Message sent successfully");


                Twilio is a subscription service, but they have a "pay as you go" plan that currently costs less than $.01 (US) per message.






                share|improve this answer













                This question bubbled up, so I thought it might be good to answer with an approach that is highly relevant today. As Farzan mentioned in a comment on his answer, there are service providers available that expose APIs which allow you to send SMS messages. This is even more relevant now as it has become somewhat rare to find landline telephones and even more rare to find a computer with a modem installed. Twilio is one of the available providers and has made sending an SMS trivial from a development perspective.



                // Twilio usings
                using Twilio;
                using Twilio.Rest.Api.V2010.Account;
                using Twilio.Types;

                const string accountSid = "your_account_sid"; // specific to your Twilio account
                const string authToken = "your_auth_token"; // specific to your Twilion account

                TwilioClient.Init(accountSid, authToken);

                // Send a new outgoing SMS by POSTing to the Messages resource
                MessageResource.Create(
                from: new PhoneNumber("555-867-5309"), // From number must be an SMS-enabled Twilio number
                to: new PhoneNumber(textBox1.Text),
                body: textBox2.Text); // Message content

                MessageBox.Show("Message sent successfully");


                Twilio is a subscription service, but they have a "pay as you go" plan that currently costs less than $.01 (US) per message.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 18 '17 at 10:48









                Kyle BurnsKyle Burns

                870313




                870313























                    -1














                    Please try this code:



                    private void Send()
                    {
                    SerialPort sp = new SerialPort();
                    sp.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived);
                    sp.PortName = "COM4";//choose your port wisely
                    sp.BaudRate = 9600;
                    sp.Parity = Parity.None;
                    sp.Open();

                    // Set the GSM modem to Text Mode
                    sp.WriteLine("AT+CMGF=1"+Environment.NewLine);
                    // Specifying mobile number
                    sp.WriteLine(string.Format("AT+CMGS="+91{0}"{1}", textBox1.Text, Environment.NewLine));
                    // Specifying sms body
                    sp.WriteLine(textBox2.Text + (char)26 + Environment.NewLine);
                    MessageBox.Show("Message sent successfully");
                    }

                    private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
                    {
                    SerialPort sp = (SerialPort)sender;
                    string modemResult = sp.ReadExisting();
                    this.yourTextBox.Text += modemResult;
                    }


                    Hope it helps






                    share|improve this answer


























                    • Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

                      – user3171896
                      Jan 11 '14 at 18:52











                    • We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

                      – Farzan
                      Jan 13 '14 at 0:50











                    • hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

                      – amateur programmer
                      Sep 8 '15 at 11:27











                    • @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

                      – Farzan
                      Sep 13 '15 at 21:47













                    • @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

                      – amateur programmer
                      Sep 14 '15 at 13:29
















                    -1














                    Please try this code:



                    private void Send()
                    {
                    SerialPort sp = new SerialPort();
                    sp.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived);
                    sp.PortName = "COM4";//choose your port wisely
                    sp.BaudRate = 9600;
                    sp.Parity = Parity.None;
                    sp.Open();

                    // Set the GSM modem to Text Mode
                    sp.WriteLine("AT+CMGF=1"+Environment.NewLine);
                    // Specifying mobile number
                    sp.WriteLine(string.Format("AT+CMGS="+91{0}"{1}", textBox1.Text, Environment.NewLine));
                    // Specifying sms body
                    sp.WriteLine(textBox2.Text + (char)26 + Environment.NewLine);
                    MessageBox.Show("Message sent successfully");
                    }

                    private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
                    {
                    SerialPort sp = (SerialPort)sender;
                    string modemResult = sp.ReadExisting();
                    this.yourTextBox.Text += modemResult;
                    }


                    Hope it helps






                    share|improve this answer


























                    • Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

                      – user3171896
                      Jan 11 '14 at 18:52











                    • We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

                      – Farzan
                      Jan 13 '14 at 0:50











                    • hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

                      – amateur programmer
                      Sep 8 '15 at 11:27











                    • @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

                      – Farzan
                      Sep 13 '15 at 21:47













                    • @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

                      – amateur programmer
                      Sep 14 '15 at 13:29














                    -1












                    -1








                    -1







                    Please try this code:



                    private void Send()
                    {
                    SerialPort sp = new SerialPort();
                    sp.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived);
                    sp.PortName = "COM4";//choose your port wisely
                    sp.BaudRate = 9600;
                    sp.Parity = Parity.None;
                    sp.Open();

                    // Set the GSM modem to Text Mode
                    sp.WriteLine("AT+CMGF=1"+Environment.NewLine);
                    // Specifying mobile number
                    sp.WriteLine(string.Format("AT+CMGS="+91{0}"{1}", textBox1.Text, Environment.NewLine));
                    // Specifying sms body
                    sp.WriteLine(textBox2.Text + (char)26 + Environment.NewLine);
                    MessageBox.Show("Message sent successfully");
                    }

                    private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
                    {
                    SerialPort sp = (SerialPort)sender;
                    string modemResult = sp.ReadExisting();
                    this.yourTextBox.Text += modemResult;
                    }


                    Hope it helps






                    share|improve this answer















                    Please try this code:



                    private void Send()
                    {
                    SerialPort sp = new SerialPort();
                    sp.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived);
                    sp.PortName = "COM4";//choose your port wisely
                    sp.BaudRate = 9600;
                    sp.Parity = Parity.None;
                    sp.Open();

                    // Set the GSM modem to Text Mode
                    sp.WriteLine("AT+CMGF=1"+Environment.NewLine);
                    // Specifying mobile number
                    sp.WriteLine(string.Format("AT+CMGS="+91{0}"{1}", textBox1.Text, Environment.NewLine));
                    // Specifying sms body
                    sp.WriteLine(textBox2.Text + (char)26 + Environment.NewLine);
                    MessageBox.Show("Message sent successfully");
                    }

                    private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
                    {
                    SerialPort sp = (SerialPort)sender;
                    string modemResult = sp.ReadExisting();
                    this.yourTextBox.Text += modemResult;
                    }


                    Hope it helps







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jan 13 '14 at 0:42

























                    answered Jan 10 '14 at 20:52









                    FarzanFarzan

                    365517




                    365517













                    • Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

                      – user3171896
                      Jan 11 '14 at 18:52











                    • We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

                      – Farzan
                      Jan 13 '14 at 0:50











                    • hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

                      – amateur programmer
                      Sep 8 '15 at 11:27











                    • @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

                      – Farzan
                      Sep 13 '15 at 21:47













                    • @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

                      – amateur programmer
                      Sep 14 '15 at 13:29



















                    • Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

                      – user3171896
                      Jan 11 '14 at 18:52











                    • We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

                      – Farzan
                      Jan 13 '14 at 0:50











                    • hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

                      – amateur programmer
                      Sep 8 '15 at 11:27











                    • @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

                      – Farzan
                      Sep 13 '15 at 21:47













                    • @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

                      – amateur programmer
                      Sep 14 '15 at 13:29

















                    Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

                    – user3171896
                    Jan 11 '14 at 18:52





                    Dear friend Farzan, thank you for your kind help. but it's not working. the message box showing the message.but didn't get the message to the phone number that i chooses.

                    – user3171896
                    Jan 11 '14 at 18:52













                    We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

                    – Farzan
                    Jan 13 '14 at 0:50





                    We need to track down the issue, first let's see what is the modem's answer! I have updated the code. Please place a TextBox on your form and set its Multiline property to true then change the code appropriately so that the incoming data will be placed into your TextBox. Try to send the message again and see what is the data shown in textbox, copy the incoming data here if it didn't help you solve the issue.

                    – Farzan
                    Jan 13 '14 at 0:50













                    hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

                    – amateur programmer
                    Sep 8 '15 at 11:27





                    hello, do i need to buy a service or anything for this to work? and the serial port is set based on what? sorry for my questions but this is my first time trying to send SMS through code.

                    – amateur programmer
                    Sep 8 '15 at 11:27













                    @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

                    – Farzan
                    Sep 13 '15 at 21:47







                    @amateurprogrammer You need to buy a GSM modem which has API documentation for developers and insert a SIM card from a operator of your choice into it. Then u r good to go. Of course a few companies provide API access so you can use their system to send your SMS. This is a better approach if you want to send SMS in Bulk.

                    – Farzan
                    Sep 13 '15 at 21:47















                    @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

                    – amateur programmer
                    Sep 14 '15 at 13:29





                    @Farzan thanks a lot, yes I came across the API access and used it and it worked :)

                    – amateur programmer
                    Sep 14 '15 at 13:29


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21053274%2fsending-sms-to-mobile-phone-in-c-net-windows-application-with-mts-modem%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks