C # SMS Send mail send

Source: Internet
Author: User
Tags mailmessage smtpclient

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.