如何使用C#从Winform应用程序向手机发送SMS ??? [英] How to send SMS from Winform Application to Mobile phone using C#???

查看:94
本文介绍了如何使用C#从Winform应用程序向手机发送SMS ???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#入门者,我不知道如何开始为小型winform应用程序编码以将消息发送到手机.
此应用程序可能未使用免费的Web服务,必须有3个文本框,用户才能从(和)手机号码,短信中输入内容,然后单击发送"就可以了.

解决方案

您可以通过调制解调器从Winform应用程序向手机发送短信.
您必须知道调制解调器连接到哪个端口.

using System.IO.Ports;

SerialPort srpModemPort = null;

            string port_name = "COM1";
            srpModemPort = new SerialPort();
            srpModemPort.PortName = port_name;
            srpModemPort.BaudRate = 115200;
            srpModemPort.Parity = Parity.None;
            srpModemPort.DataBits = 8;
            srpModemPort.StopBits = StopBits.One;
            srpModemPort.Handshake = Handshake.RequestToSend;
            srpModemPort.DtrEnable = true;
            srpModemPort.RtsEnable = true;
            srpModemPort.NewLine = System.Environment.NewLine;
            srpModemPort.WriteTimeout = 2000;

Then you can send sms by this ->

            string mobile_number = "+88XXXXXXXXXXX";
            string message = "Hi";
           
            try
            {
                if (!srpModemPort.IsOpen)
                    srpModemPort.Open();
                srpModemPort.WriteLine("AT+CMGS=" + mobile_number + "\r" + message + (char)(26));

                MessageBox.Show("Message Send.....");

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


ThaoND,

->我的代码只是将port_name修改为#Quote#COM3#Quote#.

您必须更改mobile_number.
您的端口名称可能不正确,要进行检查,请转到通讯中的huper终端菜单并尝试与调制解调器连接.

在代码项目"中的文章中搜索.有几个例子.

否则,请使用搜索引擎.


I''m a beginer C#, and i don''t know how to start coding for small winform app to send message to a cell phone.
This application may be not using free webservices, have to 3 textbox to users can input from(and) mobile number, text message and then have one button Send is ok.

Experts coder, pls tell me how to?

解决方案

You can send sms from Winform Application to Mobile phone by modem.
you have to know which port the modem is connected.

using System.IO.Ports;

SerialPort srpModemPort = null;

            string port_name = "COM1";
            srpModemPort = new SerialPort();
            srpModemPort.PortName = port_name;
            srpModemPort.BaudRate = 115200;
            srpModemPort.Parity = Parity.None;
            srpModemPort.DataBits = 8;
            srpModemPort.StopBits = StopBits.One;
            srpModemPort.Handshake = Handshake.RequestToSend;
            srpModemPort.DtrEnable = true;
            srpModemPort.RtsEnable = true;
            srpModemPort.NewLine = System.Environment.NewLine;
            srpModemPort.WriteTimeout = 2000;

Then you can send sms by this ->

            string mobile_number = "+88XXXXXXXXXXX";
            string message = "Hi";
           
            try
            {
                if (!srpModemPort.IsOpen)
                    srpModemPort.Open();
                srpModemPort.WriteLine("AT+CMGS=" + mobile_number + "\r" + message + (char)(26));

                MessageBox.Show("Message Send.....");

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


ThaoND,

--> My code is only modify port_name to #Quote#COM3#Quote#.

you have to change the mobile_number.
Your port name may be wrong, to check it, go to the huper terminal menu in communications & try to connect with the modem. In which port you will connect modem to huper terminal, use that port name of this code, And before the code run, you have to disconnect huper terminal from the modem :D I hope it will help.


Search in the Articles here on Code Project. There are several examples.

Otherwise use a search engine.


这篇关于如何使用C#从Winform应用程序向手机发送SMS ???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆