当前位置:编程学习 > C#/ASP.NET >>

networkstream发邮件发不出去

本人菜鸟,不知道哪里有问题,请大神帮我看看
  public NetworkStream getstream()
        {
            System.Net.IPAddress ipaddress = (System.Net.IPAddress)System.Net.Dns.Resolve("smtp.qq.com").AddressList.GetValue(0);
            System.Net.IPEndPoint endpoint = new System.Net.IPEndPoint(ipaddress,25);
            TcpClient ks = new TcpClient();
            ks.Connect(endpoint);
            
            return ks.GetStream();
        }
        public void smtpsend(string command)
        {
            NetworkStream ns = getstream();
            byte[] WriteBuffer;
            WriteBuffer = new byte[1024];
            WriteBuffer = Encoding.Default.GetBytes(command+"\r\n");
            ns.Write(WriteBuffer, 0, WriteBuffer.Length);
            int StreamSize;
            StreamSize = ns.Read(WriteBuffer, 0, WriteBuffer.Length);
            
             ns.Flush(); 
            //MessageBox.Show(Encoding.Default.GetString(WriteBuffer));


        }


public void sendmail(string username, string password)
        {
            smtpsend("EHLO   Localhost");
            smtpsend("AUTH LOGIN");
            string user = Convert.ToBase64String(ASCIIEncoding.Default.GetBytes("用户名"));
            string pwd = Convert.ToBase64String(ASCIIEncoding.Default.GetBytes("**********"));
            smtpsend(user);
            smtpsend(pwd);
            smtpsend("Date:   "+DateTime.Now);
            smtpsend("From: 发件人");
            smtpsend("Subject:  I LIKE  ");
            smtpsend("To: 收件人");
            smtpsend("Content-Type:   text/html;charset=gb2312");
            smtpsend("Reply-To:回件人");
            smtpsend("Content-Transfer-Encoding: do you like me");
            smtpsend("X-Mailer:DS   Mail   Sender   V1.0");
}
--------------------编程问答-------------------- 剛用了個System.Net.MailMessage成功寫了一個發送郵件的例子,
坐等一下NetworkStream是如何發送的。
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,