当前位置: 首页 > news >正文

发送邮件代码--ASP.NET中常用代码之一

1,使用Asp.net 实现邮件系统
<summary>

 2 InBlock.gif         ///  功能:实现在Web页面中发送Email
 3 ExpandedBlockEnd.gif         ///   </summary>
 4 None.gif          private   void  SendMail()
 5 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 6InBlock.gif            MailMessage m = new MailMessage();
 7InBlock.gif            
 8ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////发件人地址
 9InBlock.gif            m.From = tbFrom.Text;
10InBlock.gif
11ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////收件人地址
12InBlock.gif            m.To = tbTo.Text;
13InBlock.gif
14ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////邮件主题
15InBlock.gif            m.Subject = tbSubject.Text;
16InBlock.gif
17ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////邮件内容
18InBlock.gif            m.Body = tbBody.Text;
19InBlock.gif
20ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////优先级
21InBlock.gif            switch(ddlp.SelectedIndex)
22ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
23InBlock.gif                case 0:
24InBlock.gif                    m.Priority = MailPriority.High;
25InBlock.gif                    break;
26InBlock.gif                case 1:
27InBlock.gif                    m.Priority = MailPriority.Low;
28InBlock.gif                    break;
29InBlock.gif                default:
30InBlock.gif                    m.Priority = MailPriority.Normal;
31InBlock.gif                    break;
32ExpandedSubBlockEnd.gif            }

33InBlock.gif
34ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////设置邮件格式
35InBlock.gif            if(ddlp.SelectedIndex==0)
36InBlock.gif                m.BodyFormat = MailFormat.Text;
37InBlock.gif            else
38InBlock.gif                m.BodyFormat = MailFormat.Html;
39InBlock.gif
40ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////设置服务器
41InBlock.gif            if(tbServer.Text!="")
42ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
43InBlock.gif                SmtpMail.SmtpServer = tbServer.Text;
44ExpandedSubBlockEnd.gif            }

45InBlock.gif
46ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////以下处理附件 
47InBlock.gif            string strFileName = FileSelect.PostedFile.FileName;
48InBlock.gif            if(strFileName!="")
49InBlock.gif                m.Attachments.Add(new MailAttachment(strFileName));
50InBlock.gif
51ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////发送邮件
52InBlock.gif            SmtpMail.Send(m);
53ExpandedBlockEnd.gif        }


2利用socket接受邮件
ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
 2InBlock.gif        /// 接收邮件
 3ExpandedBlockEnd.gif        /// </summary>

 4 None.gif          private   void  SocketPopMail()
 5 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 6InBlock.gif            POP3 pop = new POP3(tbServer.Text,tbUser.Text,tbPass.Text);
 7InBlock.gif            int n = pop.GetNumberOfNewMessages();
 8InBlock.gif            if(n==-1)
 9ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
10InBlock.gif                Response.Write("<script language='javascript'>alert('服务器连接错误!')</script>");
11InBlock.gif                return;
12ExpandedSubBlockEnd.gif            }

13InBlock.gif            ddlNew.Items.Clear();
14InBlock.gif            for(int i=1;i<=n;i++)
15InBlock.gif                ddlNew.Items.Add(""+i.ToString()+"封邮件");
16InBlock.gif            if(n>0)
17ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
18InBlock.gif                MailMessage msg =  pop.GetNewMessages(0);
19InBlock.gif                if(msg!=null)
20InBlock.gif                    tbBody.Text = msg.Body;
21ExpandedSubBlockEnd.gif            }

22ExpandedBlockEnd.gif        }
pop3类的实现如下:
1ExpandedBlockStart.gifContractedBlock.gif/**//// <summary>
  2InBlock.gif    /// 接收邮件类
  3ExpandedBlockEnd.gif    /// </summary>

  4None.gif    public class POP3
  5ExpandedBlockStart.gifContractedBlock.gif    dot.gif{
  6InBlock.gif        string POPServer;
  7InBlock.gif        string user;
  8InBlock.gif        string pwd;
  9InBlock.gif        NetworkStream ns;
 10InBlock.gif        StreamReader sr;
 11InBlock.gif
 12ExpandedSubBlockStart.gifContractedSubBlock.gif        public POP3()dot.gif{}
 13InBlock.gif
 14InBlock.gif        public POP3(string server, string _user, string _pwd)
 15ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 16InBlock.gif            POPServer = server;
 17InBlock.gif            user = _user;
 18InBlock.gif            pwd = _pwd;
 19ExpandedSubBlockEnd.gif        }

 20InBlock.gif        
 21ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 22InBlock.gif        /// 连接服务器
 23InBlock.gif        /// </summary>
 24ExpandedSubBlockEnd.gif        /// <returns></returns>

 25InBlock.gif        private bool Connect()
 26ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 27InBlock.gif            TcpClient sender = new TcpClient(POPServer,110);
 28InBlock.gif            byte[] outbytes;
 29InBlock.gif            string input;
 30InBlock.gif
 31InBlock.gif            try
 32ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 33InBlock.gif                ns = sender.GetStream();
 34InBlock.gif                sr = new StreamReader(ns);
 35InBlock.gif
 36InBlock.gif                sr.ReadLine();
 37InBlock.gif                input = "user " + user + "\r\n";
 38InBlock.gif                outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
 39InBlock.gif                ns.Write(outbytes,0,outbytes.Length) ;
 40InBlock.gif                sr.ReadLine();
 41InBlock.gif            
 42InBlock.gif                input = "pass " + pwd + "\r\n";
 43InBlock.gif                outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
 44InBlock.gif                ns.Write(outbytes,0,outbytes.Length) ;
 45InBlock.gif                sr.ReadLine();
 46InBlock.gif                return true;  
 47InBlock.gif        
 48ExpandedSubBlockEnd.gif            }

 49InBlock.gif            catch
 50ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 51InBlock.gif                return false;
 52ExpandedSubBlockEnd.gif            }

 53ExpandedSubBlockEnd.gif        }

 54InBlock.gif        
 55ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
 56InBlock.gif        /// 断开与服务器的连接
 57ExpandedSubBlockEnd.gif        /// </summary>

 58InBlock.gif        private void Disconnect()
 59ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 60InBlock.gif            string input = "quit" + "\r\n";
 61InBlock.gif            Byte[] outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
 62InBlock.gif            ns.Write(outbytes,0,outbytes.Length);
 63InBlock.gif            ns.Close();
 64ExpandedSubBlockEnd.gif        }

 65InBlock.gif
 66InBlock.gif        public int GetNumberOfNewMessages()
 67ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 68InBlock.gif            byte[] outbytes;
 69InBlock.gif            string input;
 70InBlock.gif
 71InBlock.gif            try
 72ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 73InBlock.gif                Connect();
 74InBlock.gif
 75InBlock.gif                input = "stat" + "\r\n";
 76InBlock.gif                outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
 77InBlock.gif                ns.Write(outbytes,0,outbytes.Length);
 78InBlock.gif                string resp = sr.ReadLine();
 79ExpandedSubBlockStart.gifContractedSubBlock.gif                string[] tokens = resp.Split(new Char[] dot.gif{' '});
 80InBlock.gif
 81InBlock.gif                Disconnect();
 82InBlock.gif
 83InBlock.gif                return Convert.ToInt32(tokens[1]);
 84ExpandedSubBlockEnd.gif            }

 85InBlock.gif            catch
 86ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 87InBlock.gif                return -1;
 88ExpandedSubBlockEnd.gif            }

 89ExpandedSubBlockEnd.gif        }

 90InBlock.gif        public ArrayList GetNewMessages(string subj)
 91ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 92InBlock.gif
 93InBlock.gif            int newcount;
 94InBlock.gif            ArrayList newmsgs = new ArrayList();
 95InBlock.gif
 96InBlock.gif            try
 97ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 98InBlock.gif                newcount = GetNumberOfNewMessages();
 99InBlock.gif                Connect();
100InBlock.gif
101InBlock.gif                for(int n=1; n<newcount+1; n++)
102ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
103InBlock.gif                    ArrayList msglines = GetRawMessage(n);
104InBlock.gif                    string msgsubj = GetMessageSubject(msglines);
105InBlock.gif                    if(msgsubj.CompareTo(subj) == 0)
106ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
107InBlock.gif                        System.Web.Mail.MailMessage msg = new MailMessage();
108InBlock.gif                        msg.Subject = msgsubj;
109InBlock.gif                        msg.From = GetMessageFrom(msglines);
110InBlock.gif                        msg.Body = GetMessageBody(msglines);
111InBlock.gif                        newmsgs.Add(msg);
112InBlock.gif                        DeleteMessage(n);
113ExpandedSubBlockEnd.gif                    }

114ExpandedSubBlockEnd.gif                }

115InBlock.gif
116InBlock.gif                Disconnect();
117InBlock.gif                return newmsgs;
118ExpandedSubBlockEnd.gif            }

119InBlock.gif            catch(Exception e)
120ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
121InBlock.gif                return newmsgs;
122ExpandedSubBlockEnd.gif            }

123ExpandedSubBlockEnd.gif        }

124InBlock.gif
125ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
126InBlock.gif        /// 获取新邮件
127InBlock.gif        /// </summary>
128InBlock.gif        /// <param name="nIndex"></param>
129ExpandedSubBlockEnd.gif        /// <returns></returns>

130InBlock.gif        public MailMessage GetNewMessages(int nIndex)
131ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
132InBlock.gif            int newcount;
133InBlock.gif            System.Web.Mail.MailMessage msg = new MailMessage();
134InBlock.gif
135InBlock.gif            try
136ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
137InBlock.gif                newcount = GetNumberOfNewMessages();
138InBlock.gif                Connect();
139InBlock.gif                int n = nIndex+1;
140InBlock.gif
141InBlock.gif                if(n<newcount+1)
142ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
143InBlock.gif                    ArrayList msglines = GetRawMessage(n);
144InBlock.gif                    string msgsubj = GetMessageSubject(msglines);
145InBlock.gif                
146InBlock.gif                    
147InBlock.gif                    msg.Subject = msgsubj;
148InBlock.gif                    msg.From = GetMessageFrom(msglines);
149InBlock.gif                    msg.Body = GetMessageBody(msglines);
150ExpandedSubBlockEnd.gif                }

151InBlock.gif
152InBlock.gif                Disconnect();
153InBlock.gif                return msg;
154ExpandedSubBlockEnd.gif            }

155InBlock.gif            catch
156ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
157InBlock.gif                return null;
158ExpandedSubBlockEnd.gif            }

159ExpandedSubBlockEnd.gif        }

160InBlock.gif        private ArrayList GetRawMessage (int messagenumber)
161ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
162InBlock.gif            Byte[] outbytes;
163InBlock.gif            string input;
164InBlock.gif            string line = "";
165InBlock.gif
166InBlock.gif            input = "retr " + messagenumber.ToString() + "\r\n";
167InBlock.gif            outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
168InBlock.gif            ns.Write(outbytes,0,outbytes.Length);
169InBlock.gif
170InBlock.gif            ArrayList msglines = new ArrayList();
171InBlock.gif            do
172ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
173InBlock.gif                line = sr.ReadLine();
174InBlock.gif                msglines.Add(line);
175ExpandedSubBlockEnd.gif            }
 while (line != ".");
176InBlock.gif            msglines.RemoveAt(msglines.Count-1);
177InBlock.gif
178InBlock.gif            return msglines;
179ExpandedSubBlockEnd.gif        }

180InBlock.gif
181ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
182InBlock.gif        /// 获取邮件主题
183InBlock.gif        /// </summary>
184InBlock.gif        /// <param name="msglines"></param>
185ExpandedSubBlockEnd.gif        /// <returns></returns>

186InBlock.gif        private string GetMessageSubject(ArrayList msglines)
187ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
188InBlock.gif            string[] tokens;
189InBlock.gif            IEnumerator msgenum = msglines.GetEnumerator();
190InBlock.gif            while (msgenum.MoveNext() )
191ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
192InBlock.gif                string line = (string)msgenum.Current;
193InBlock.gif                if(line.StartsWith("Subject:") )
194ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
195ExpandedSubBlockStart.gifContractedSubBlock.gif                    tokens = line.Split(new Char[] dot.gif{' '});
196InBlock.gif                    return tokens[1].Trim();
197ExpandedSubBlockEnd.gif                }

198ExpandedSubBlockEnd.gif            }

199InBlock.gif            return "None";
200ExpandedSubBlockEnd.gif        }

201InBlock.gif
202ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
203InBlock.gif        /// 获取邮件源地址
204InBlock.gif        /// </summary>
205InBlock.gif        /// <param name="msglines"></param>
206ExpandedSubBlockEnd.gif        /// <returns></returns>

207InBlock.gif        private string GetMessageFrom (ArrayList msglines)
208ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
209InBlock.gif            string[] tokens;
210InBlock.gif            IEnumerator msgenum = msglines.GetEnumerator();
211InBlock.gif            while (msgenum.MoveNext() )
212ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
213InBlock.gif                string line = (string)msgenum.Current;
214InBlock.gif                if(line.StartsWith("From:") )
215ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
216ExpandedSubBlockStart.gifContractedSubBlock.gif                    tokens = line.Split(new Char[] dot.gif{'<'});
217ExpandedSubBlockStart.gifContractedSubBlock.gif                    return tokens[1].Trim(new Char[] dot.gif{'<','>'});
218ExpandedSubBlockEnd.gif                }

219ExpandedSubBlockEnd.gif            }

220InBlock.gif            return "None";
221ExpandedSubBlockEnd.gif        }

222InBlock.gif
223ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
224InBlock.gif        /// 获取邮件内容
225InBlock.gif        /// </summary>
226InBlock.gif        /// <param name="msglines"></param>
227ExpandedSubBlockEnd.gif        /// <returns></returns>

228InBlock.gif        private string GetMessageBody(ArrayList msglines)
229ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
230InBlock.gif            string body = "";
231InBlock.gif            string line = " ";
232InBlock.gif            IEnumerator msgenum = msglines.GetEnumerator();
233InBlock.gif
234InBlock.gif            while(line.CompareTo(""!= 0)
235ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
236InBlock.gif                msgenum.MoveNext();
237InBlock.gif                line = (string)msgenum.Current;
238ExpandedSubBlockEnd.gif            }

239InBlock.gif
240InBlock.gif            while (msgenum.MoveNext() )
241ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
242InBlock.gif                body = body + (string)msgenum.Current + "\r\n";
243ExpandedSubBlockEnd.gif            }

244InBlock.gif            return body;
245ExpandedSubBlockEnd.gif        }

246InBlock.gif
247ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
248InBlock.gif        /// 删除邮件
249InBlock.gif        /// </summary>
250ExpandedSubBlockEnd.gif        /// <param name="messagenumber"></param>

251InBlock.gif        private void DeleteMessage(int messagenumber)
252ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
253InBlock.gif            Byte[] outbytes;
254InBlock.gif            string input;
255InBlock.gif
256InBlock.gif            try
257ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
258InBlock.gif                input = "dele " + messagenumber.ToString() + "\r\n";
259InBlock.gif                outbytes = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
260InBlock.gif                ns.Write(outbytes,0,outbytes.Length);
261ExpandedSubBlockEnd.gif            }

262InBlock.gif            catch(Exception e)
263ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
264InBlock.gif                return;
265ExpandedSubBlockEnd.gif            }

266InBlock.gif
267ExpandedSubBlockEnd.gif        }

268InBlock.gif
269ExpandedBlockEnd.gif    }
3利用socket发送邮件
ExpandedBlockStart.gifContractedBlock.gif/**//// <summary>
 2InBlock.gif        /// 功能:利用Socket来发送邮件
 3ExpandedBlockEnd.gif        /// </summary>

 4None.gif        private void SocketSendMail()
 5ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 6InBlock.gif            SMTP smtp = new SMTP();
 7InBlock.gif            bool bSuccess = smtp.Send(tbSmtp.Text,25,tbSend.Text,tbReceive.Text,tbSubject.Text,tbBody.Text);
 8InBlock.gif            if(bSuccess)
 9InBlock.gif                Response.Write("<script language='javascript'>alert('邮件发送成功!')</script>");
10InBlock.gif            else
11InBlock.gif                Response.Write("<script language='javascript'>alert('邮件发送失败!')</script>");
12ExpandedBlockEnd.gif        }
smtp类的实现如下:
1ExpandedBlockStart.gifContractedBlock.gif/**//// <summary>
 2InBlock.gif    /// 发送邮件类
 3ExpandedBlockEnd.gif    /// </summary>
 4None.gif    public class SMTP
 5ExpandedBlockStart.gifContractedBlock.gif    dot.gif{
 6ExpandedSubBlockStart.gifContractedSubBlock.gif        public SMTP()dot.gif{}
 7InBlock.gif
 8InBlock.gif        public bool Send(string strSmtpServer,int nPort,string strSend,string strReceive
 9InBlock.gif            ,string strSubject,string strContent)
10ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
11ExpandedSubBlockStart.gifContractedSubBlock.gif            /**//// smtp服务器的IP地址  
12InBlock.gif            string smtpserver=strSmtpServer;
13InBlock.gif            TcpClient tcpc = new TcpClient();
14InBlock.gif            try
15ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
16InBlock.gif                tcpc.Connect(smtpserver, nPort);
17InBlock.gif                StreamReader sr ;
18InBlock.gif                string strCmd;
19InBlock.gif                sr = new StreamReader(tcpc.GetStream(),Encoding.Default);
20InBlock.gif
21ExpandedSubBlockStart.gifContractedSubBlock.gif                /**////服务器连接成功以后,首先向服务器发送HeLlo命令
22InBlock.gif                strCmd="HELO shaozhd";
23InBlock.gif                SenSmtpCmd(tcpc,strCmd);
24InBlock.gif
25ExpandedSubBlockStart.gifContractedSubBlock.gif                /**////然后向服务器发送信件的成员的信箱
26InBlock.gif                strCmd="mail from:"+ strSend;
27InBlock.gif                SenSmtpCmd(tcpc,strCmd);
28InBlock.gif
29ExpandedSubBlockStart.gifContractedSubBlock.gif                /**////向服务器发送收件人的信箱
30InBlock.gif                strCmd="rcpt to:" + strReceive;
31InBlock.gif                SenSmtpCmd(tcpc,strCmd);
32InBlock.gif
33ExpandedSubBlockStart.gifContractedSubBlock.gif                /**////所有的准备工作都已经作好了,下面开始进行邮件的部分
34InBlock.gif                strCmd="data";
35InBlock.gif                SenSmtpCmd(tcpc,strCmd);
36InBlock.gif
37ExpandedSubBlockStart.gifContractedSubBlock.gif                /**////邮件内容
38InBlock.gif                strCmd="Date: 1234567\r\n";
39InBlock.gif                strCmd=strCmd+"From: " + strSend +"\r\n";
40InBlock.gif                strCmd=strCmd+"To: " + strReceive +"\r\n";
41InBlock.gif                strCmd=strCmd+"Subject: " + strSubject +"\r\n\r\n";
42InBlock.gif                strCmd=strCmd + strContent +"\r\n\r\n";
43InBlock.gif                SenSmtpCmd(tcpc,strCmd);
44InBlock.gif                strCmd="\r\n.\r\n";
45InBlock.gif                SenSmtpCmd(tcpc,strCmd);
46InBlock.gif
47ExpandedSubBlockStart.gifContractedSubBlock.gif                /**////最后 关闭与smtp 服务器的连接
48InBlock.gif              tcpc.Close();
49InBlock.gif                return true;
50ExpandedSubBlockEnd.gif             }

51InBlock.gif            catch
52ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
53InBlock.gif                return false;
54ExpandedSubBlockEnd.gif            }

55ExpandedSubBlockEnd.gif        }

56InBlock.gif
57ExpandedSubBlockStart.gifContractedSubBlock.gif        /**//// <summary>
58InBlock.gif        /// 发送SMTP命令
59InBlock.gif        /// </summary>
60InBlock.gif        /// <param name="tcpc"></param>
61ExpandedSubBlockEnd.gif        /// <param name="strCmd"></param>

62InBlock.gif        void SenSmtpCmd(TcpClient tcpc,String strCmd)
63ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
64InBlock.gif
65InBlock.gif         byte[] arrCmd;
66InBlock.gif          string strRet;
67InBlock.gif          StreamReader sr;
68InBlock.gif        Stream s;
69InBlock.gif        s=tcpc.GetStream();
70InBlock.gif        strCmd = strCmd + "\r\n";
71InBlock.gif        arrCmd= Encoding.Default.GetBytes(strCmd.ToCharArray()); 
72InBlock.gif        s=tcpc.GetStream();
73InBlock.gif        s.Write(arrCmd, 0, strCmd.Length);
74InBlock.gif
75ExpandedSubBlockStart.gifContractedSubBlock.gif            /**////以下用于程序调试,显示服务器回应信息
76InBlock.gif        sr = new StreamReader(tcpc.GetStream(), Encoding.Default);
77InBlock.gif        strRet=sr.ReadLine();
78InBlock.gif        return;
79ExpandedSubBlockEnd.gif        }

80ExpandedBlockEnd.gif    }

转自 http://Teerylee.cnblogs.com/

转载于:https://www.cnblogs.com/sutengcn/archive/2005/12/06/291512.html

相关文章:

  • css在线sprite
  • C#中的类型转换
  • 20180925 SQL Server游标使用
  • 青蛙
  • jQuery介绍
  • SmartPersistenceLayer 3.1 事务处理
  • idea项目结构旁边出现0%classes,0%lines covered
  • 陌生女孩
  • 更简单高效的HTML数据提取-Xpath
  • 唐伯虎之作收录
  • java数据结构---------插入排序的实现
  • Enterprise Library2.0(2):Logging Application Block学习
  • 深入理解.NET Core的基元: deps.json, runtimeconfig.json, dll文件
  • 常见的网站攻击手段和防御方法
  • 致爱我的人和我爱的人
  • 【EOS】Cleos基础
  • Asm.js的简单介绍
  • ECMAScript6(0):ES6简明参考手册
  • IOS评论框不贴底(ios12新bug)
  • JavaScript类型识别
  • Joomla 2.x, 3.x useful code cheatsheet
  • Median of Two Sorted Arrays
  • Octave 入门
  • scrapy学习之路4(itemloder的使用)
  • Vue小说阅读器(仿追书神器)
  • 笨办法学C 练习34:动态数组
  • 读懂package.json -- 依赖管理
  • 关于springcloud Gateway中的限流
  • 关于字符编码你应该知道的事情
  • 聊一聊前端的监控
  • 七牛云假注销小指南
  • 全栈开发——Linux
  • 少走弯路,给Java 1~5 年程序员的建议
  • 第二十章:异步和文件I/O.(二十三)
  • 回归生活:清理微信公众号
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • ###C语言程序设计-----C语言学习(6)#
  • #宝哥教你#查看jquery绑定的事件函数
  • (+4)2.2UML建模图
  • (ZT)出版业改革:该死的死,该生的生
  • (二)【Jmeter】专栏实战项目靶场drupal部署
  • (南京观海微电子)——I3C协议介绍
  • (转)memcache、redis缓存
  • ****Linux下Mysql的安装和配置
  • **Java有哪些悲观锁的实现_乐观锁、悲观锁、Redis分布式锁和Zookeeper分布式锁的实现以及流程原理...
  • .FileZilla的使用和主动模式被动模式介绍
  • .Net 代码性能 - (1)
  • .NET 使用配置文件
  • .NET连接数据库方式
  • .net与java建立WebService再互相调用
  • @Autowired和@Resource装配
  • @staticmethod和@classmethod的作用与区别
  • @Transactional类内部访问失效原因详解
  • [ SNOI 2013 ] Quare