Interest is the best teacher. --Einstein
First, the realization of SMS delivery
1. Use SMS Mao's way to send text messages, the premise to buy hardware equipment, here is not considered to show;
2. Using the SMS platform provided by China network, but after a few times to charge;
We mainly introduce the second way to achieve SMS, in the online (http://sms.webchinese.cn/) registered account (note password is not the key to obtain the SMS), the specific implementation, you can refer to the SMS API Downstream interface (HTTP/ sms.webchinese.cn/api.shtml), multi-language implementation examples are, the author here in C # implementation
Here is the Code demo
Private stringstrURL ="http://utf8.sms.webchinese.cn/?"; Private stringStruid ="uid="; Private stringStrkey ="&key="; Private stringStrsmsmon ="&smsmob="; Private stringStrsmstext ="&smstext="; PublicMainForm () {InitializeComponent (); } Private voidBtnsend_click (Objectsender, EventArgs e) { if(txtsmsuserid.text!=""&& txttel.text!=""&& Txtsmsuserid.text! ="") { stringurl = strurl + struid + txtsmsuserid.text + strkey + strsmsmon + txttel.text + strsmstext +Txtcontent.text; stringresult=gethtmlfromurl (URL); MessageBox.Show (result); } } Private stringGethtmlfromurl (stringURL) { stringTargetUrl =URL. Trim (). ToString (); stringresult =NULL; Try{HttpWebRequest Request=(HttpWebRequest) webrequest.create (TargetUrl); Request. UserAgent="mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; Request. Method="GET"; Request. Timeout= -* -* +; WebResponse response=request. GetResponse (); Stream Stream=Response. GetResponseStream (); StreamReader Reader=NewStreamReader (stream, Encoding.default); Result=Reader. ReadToEnd (); } Catch(Exception ex) {Throw NewException (ex. StackTrace); } returnresult; }
Second, to achieve mail delivery
. Net provides a lot of very rich mail sending and receiving APIs in the System.Net.Mail namespace, making it easy to implement messaging functions, here is a simple email example
Here is the Code demo
Private stringSmtpservice ="smtp.dnaerp.com"; Private stringSendEmail ="[email protected]"; Private stringSendpwd =""; PublicMainForm () {InitializeComponent (); } Private voidBtnsend_click (Objectsender, EventArgs e) {SmtpClient client=NewSmtpClient (Smtpservice); MailAddress sendaddress=NewMailAddress (SendEmail,"michaeltest"); MailAddress receiveraddress=Newmailaddress (Txtreceiver.text); MailMessage message=NewMailMessage (sendaddress, receiveraddress); Message. Subject="Email Demo Test"; Message. Subjectencoding=Encoding.default; Message. Body=Txtcontent.text; Message. Bodyencoding=Encoding.default; Message. To.add (""); Message. Cc. ADD (""); Client. Deliverymethod=smtpdeliverymethod.network; //whether to enable secure SSL sendClient. Enablessl =false; Try{client. useDefaultCredentials=false; NetworkCredential Credential=NewNetworkCredential (SENDEMAIL,SENDPWD); Client. Credentials=credential; Client. Send (message); MessageBox.Show ("message sent successfully"); } Catch(Exception ex) {Throw NewException (ex. StackTrace); } }
About the implementation of sending text messages, send e-mail to the end of the study, I hope to help you, if there is insufficient, welcome treatise, thank you for your reading.
C # SMS Send mail send