using .Net.Sockets;
using .Collections;
using .IO;
using .Net;
using ;
using .Web.Mail;
public POP3
{
POPServer;
user;
pwd;
NetworkStream ns;
StreamReader sr;
public POP3{}
public POP3( server, _user, _pwd)
{
POPServer = server;
user = _user;
pwd = _pwd;
}
private void Connect
{
TcpClient sender = TcpClient(POPServer,110);
Byte outs;
input;
try
{
ns = sender.GetStream;
sr = StreamReader(ns);
sr.ReadLine;
//Console.WriteLine(sr.ReadLine );
input = \"user \" + user + \"\\r\\n\";
outs = .Text.Encoding.ASCII.GetBytes(input.ToCharArray);
ns.Write(outs,0,outs.Length) ;
sr.ReadLine;
//Console.WriteLine(sr.ReadLine );
input = \"pass \" + pwd + \"\\r\\n\";
outs = .Text.Encoding.ASCII.GetBytes(input.ToCharArray);
ns.Write(outs,0,outs.Length) ;
sr.ReadLine;
//Console.WriteLine(sr.ReadLine );
}
catch(InvalidOperationException ioe)
{
Console.WriteLine(\"Could not connect to mail server\");
}
}
private void Disconnect
{
input = \"quit\" + \"\\r\\n\";
Byte outs = .Text.Encoding.ASCII.GetBytes(input.ToCharArray);
ns.Write(outs,0,outs.Length);
//Console.WriteLine(sr.ReadLine );
ns.Close;
}
public GetNumberOfNewMessages
{
Byte outs;
input;
try
{
Connect;
input = \"stat\" + \"\\r\\n\";
outs = .Text.Encoding.ASCII.GetBytes(input.ToCharArray);
ns.Write(outs,0,outs.Length);
resp = sr.ReadLine;
//Console.WriteLine(resp);
tokens = resp.Split( Char {\' \'});
Disconnect;
Convert.ToInt32(tokens[1]);
}
catch(InvalidOperationException ioe)
{
Console.WriteLine(\"Could not connect to mail server\");
0;
}
}
public ArrayList GetNewMessages( subj)
{
count;
ArrayList msgs = ArrayList;
try
{
count = GetNumberOfNewMessages;
Connect;
for( n=1; n<count+1; n)
{
ArrayList msglines = GetRawMessage(n);
msgsubj = GetMessageSubject(msglines);
(msgsubj.CompareTo(subj) 0)
{
.Web.Mail.MailMessage msg = MailMessage;
msg.Subject = msgsubj;
msg.From = GetMessageFrom(msglines);
msg.Body = GetMessageBody(msglines);
msgs.Add(msg);
DeleteMessage(n);
&
最新评论