Access | Server this are a follow up to I SMTP example that shows I to access your POP3 server. This is the program connects and logs in to your POP3 server, and checks to the how-to-you many new messages.
The instantiation of the POP is in Main ():
Pop pop = new Pop ("Pop-server", "LoginName", "password"); You must replace ' Pop-server ' with the name of your POP server, ' LoginName ' with your own log in, and ' password ' with your Password. The class has two methods. The Connect method takes care of actually logging into to the server. The TcpClient class is used to establish the connection. The ' user ' and ' pass ' commands are used to login. Connect returns a NetworkStream object created during the connection process. The second is getnumberofnewmessages, which returns the number of unread to on the server. The response to the "stat" command are parsed to extract the number of new messages.
Requirement:
Requires. NET SDK
How to Compile?
Csc/r:system.net.dll/r:system.io.dll Pop.cs
Source Code
Using System.Net.Sockets;
Using System.IO;
Using System.Net;
Using System;
Class POP
{
String Popserver;
string user;
string pwd;
Public POP () {}
Public POP (String server, String _user, String _pwd)
{
Popserver = server;
user = _user;
PWD = _pwd;
}
Private NetworkStream Connect ()
{
TcpClient sender = new TcpClient (popserver,110);
Byte[] outbytes;
string input;
NetworkStream ns = null;
try{
NS = sender. GetStream ();
StreamReader sr = new StreamReader (NS);
Console.WriteLine (Sr. ReadLine ());
input = "User" + user + "\ r \ n";
Outbytes = System.Text.Encoding.ASCII.GetBytes (input. ToCharArray ());
Ns. Write (outbytes,0,outbytes. Length);
Console.WriteLine (Sr. ReadLine ());
Sr. Close ();
Ns. Close ();
Return tokens[1]. ToInt32 ();
}
catch (InvalidOperationException IoE) {
Console.WriteLine ("Could not connect to mail Server");
return 0;
}
}
public static void Main ()
{
Pop pop = new Pop ("Pop-server", "LoginName", "password");
Console.WriteLine ("New Messages = {0}", pop. Getnumberofnewmessages ());
Console.ReadLine ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.