標籤:oid odi suse pcl init agent eth show code
興趣是最好的老師。 --愛因斯坦
一、實現簡訊發送
1.使用簡訊mao的方式進行簡訊發送,前提要購買硬體裝置,這裡就不考慮展示了;
2.使用中國網建提供的簡訊平台,但是用幾次後要收費;
我們這裡主要介紹第二種方式實現簡訊發送,在網上(http://sms.webchinese.cn/)註冊帳號(注意密碼不是簡訊密鑰需自行擷取),具體實現,可以參考SMS簡訊通API下行介面(http://sms.webchinese.cn/api.shtml),多種語言實現例子都有,筆者這裡用C#實現
下面是代碼demo
private string strurl = "http://utf8.sms.webchinese.cn/?"; private string strUid = "Uid="; private string strKey = "&Key="; private string strsmsMon = "&smsMob="; private string strsmsText = "&smsText="; public MainForm() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { if(txtSMSUserID.Text!=""&& txtTel.Text!="" && txtSMSUserID.Text != "") { string url = strurl + strUid + txtSMSUserID.Text + strKey + strsmsMon + txtTel.Text + strsmsText + txtContent.Text; string result= GetHtmlFromUrl(url); MessageBox.Show(result); } } private string GetHtmlFromUrl(string url) { string targetUrl = url.Trim().ToString(); string result = 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 = 30 * 60 * 1000; WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream, Encoding.Default); result = reader.ReadToEnd(); } catch (Exception ex) { throw new Exception(ex.StackTrace); } return result; }
二、實現郵件發送
. NET提供了很多很豐富的郵件發送與接收的API在System.Net.Mail命名空間裡,使得實現郵件收發功能變得簡單,下面是一個簡單的郵件發送例子
下面是代碼demo
private string smtpService = "smtp.dnaerp.com"; private string sendEmail = "[email protected]"; private string sendPwd = ""; public MainForm() { InitializeComponent(); } private void btnSend_Click(object sender, EventArgs e) { SmtpClient client = new SmtpClient(smtpService); MailAddress sendAddress = new MailAddress(sendEmail,"MichaelTest"); MailAddress receiverAddress = new MailAddress(txtReceiver.Text); MailMessage message=new MailMessage(sendAddress, receiverAddress); message.Subject = "郵件demo測試"; message.SubjectEncoding = Encoding.Default; message.Body = txtContent.Text; message.BodyEncoding = Encoding.Default; message.To.Add(""); message.CC.Add(""); client.DeliveryMethod = SmtpDeliveryMethod.Network; //是否啟用ssl 安全發送 client.EnableSsl = false; try { client.UseDefaultCredentials = false; NetworkCredential credential = new NetworkCredential(sendEmail,sendPwd); client.Credentials = credential; client.Send(message); MessageBox.Show("郵件發送成功"); } catch (Exception ex) { throw new Exception(ex.StackTrace); } }
關於實現傳送簡訊,發送郵件的學習就到此結束了,希望能夠幫到你,若有不足,歡迎斧正,感謝您的閱讀。
C# 簡訊發送 郵件發送