摘要:[ASP.NET][C#]Pop3 驗證使用者
Pop3認證程式碼...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;
namespace pop3
{
class Program
{
static void Main(string[] args)
{
TcpClient tcpc = new TcpClient("pop3Server", 110);
string user, pass;
user = Console.ReadLine();
pass = Console.ReadLine();
Pop3(tcpc,user,pass);
Console.ReadKey();
}
static void Pop3(TcpClient tcpc ,string user,string pass)
{
string strRet;
NetworkStream st = tcpc.GetStream();
StreamReader sr = new StreamReader(st);
//Console.WriteLine(sr.ReadLine());
strRet = sr.ReadLine();
if (Check(strRet))
{
Console.WriteLine("連線成功!!!!");
}
else
{
Console.WriteLine("連線失敗!!");
}
string input;
input ="user "+ user+"\r\n";
Byte[] output = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
st.Write(output, 0, output.Length);
//Console.WriteLine(sr.ReadLine());
strRet = sr.ReadLine();//這行拿掉怎麼試都不行永遠都是登入成功XD!可以跟我講是為什麼@@
input = "pass " + pass + "\r\n";
output = System.Text.Encoding.ASCII.GetBytes(input.ToCharArray());
st.Write(output, 0, output.Length);
strRet = sr.ReadLine();
if (Check(strRet))
{
Console.WriteLine("登入成功");
}
else
{
Console.WriteLine("登入失敗");
}
}
static bool Check(string strRet)//判斷是否正確
{
if (strRet.Substring(0,3) == "+OK")
{
return true;
}
else
{
return false;
}
}
}
}
原始碼:pop3.rar
自己嘗試的~請多多指教:D
我只是個小小的入門者