Library tutorials & articles
How to POP3 in C#
- Introduction
- Getting Started
- Connecting and Disconnecting
- Retrieving Messages
- Removing Messages
- Supporting Functions
- Using the Class
Connecting and Disconnecting
The first method of our Pop3 class is the Connect method. This method takes a server name, username and password parameter to connect to a remote (sometimes local) POP3 server.
public void Connect(string server, string username, string
password)
{
string message;
string response;
Connect(server, 110);
response = Response();
if (response.Substring(0, 3) != "+OK")
{
throw new Pop3Exception(response);
}
message = "USER " + username + "\r\n";
Write(message);
response = Response();
if (response.Substring(0, 3) != "+OK")
{
throw new Pop3Exception(response);
}
message = "PASS " + password + "\r\n";
Write(message);
response = Response();
if (response.Substring(0, 3) != "+OK")
{
throw new Pop3Exception(response);
}
}
We begin by calling the TcpClient.Connect method passing the
server name and the 110 port. The 110 port number is the well known port number
for POP3 operations. What that means is that POP3 servers by default should
listen for connections on port 110. When the POP3 server connects to a client,
it should immediately respond with the +OK acknowledgement message.
Next we send two messages, USER and PASS, back to
the server. The POP3 server should acknowledge a successful login by acknowledging
both messages. If the POP3 server returns anything but +OK, then
the message will contain the reason for the failure. In the advent of a failure,
I attach that failure message to our exception class and throw it back to the
client. It should be noted that some POP3 servers don't require authentication
and may reject the calls to USER and PASS. I haven't
encountered such a POP3 server, but the protocol allows it. In those cases,
you'll have to slightly modify the class to make things work.
Any use of our Pop3 class should begin with a call to Connect and
end with a class to Disconnect.
public void Disconnect()
{
string message;
string response;
message = "QUIT\r\n";
Write(message);
response = Response();
if (response.Substring(0, 3) != "+OK")
{
throw new Pop3Exception(response);
}
}
The Disconnect method sends a QUIT message to the
POP3 server.
Related articles
Related podcasts
-
Moving your Email into the Cloud - Google for Apps and Live Custom Domains
Scott and Carl talk about Scott's Family's recent move to Google Apps and Carl considers moving to Live Custom Domains. What are the benefits of moving your life into the cloud?
As a professional VOB converter, Emicsoft VOB Converter is currently one of the best and most easy-to-use converter which can convert VOB videos to most popular video and audio formats with fast conversion speed and perfect sound & picture quality, such as VOB to MP3, VOB to M4A, VOB to WAV, VOB to AAC, VOB to AC3; VOB to DVD Video(.vob), DVD Video-NTSC(.vob), MPEG-1 Video(.mpg), MPEG-2 Video (.mpg), etc.
Emicsoft VOB Converter can not only play the role as a converter, moreover, it can also be used as a powerful editor, which provides a lot of professional video editing functions, such as merging several videos into one file, cutting any clip of your video, cropping the video size, editing video effect and so on. You can also set output profile parameters including resolution, bitrate, frame rate, aspect ratio to get the best video quality and video size.
How to convert VOB to other formats?
Emicsoft VOB Converter is so outstanding with powerful converting functions and editing functions that you can enjoy it as a good helper.
Emicsoft M2TS Converter is currently considered as one of the most professional conversion tool, due to its powerful function, user-friendly interface and easy-to-use operation design. It can achieve any video formats from M2TS to MPEG1, MPEG2, SWF, FLV, DivX, XviD, QuickTime Video, DV, AVI, MP4, WMV and HD videos, so as to make it available to sync M2TS to iPod, iPhone, PSP, BlackBerry and other mobile devices.
Emicsoft Tod Converter is an easy-to-use HD Video conversion tool which helps you convert HD video Tod to other formats like FLV, SWF, AVI, M4V, MOV, DivX, XviD, MPEG-1, MPEG-2, VOB, MP4, M4V, RM, RMVB, WMV, MKV, AVI, 3GP, HD video with high output quality and fast converting speed. Apart from as a HD video converter, it is also a audio converter and extractor, the Emicsoft Tod Converter can aid you to extract music from Tod video such as WAV, OGG, WMA, MP3 with good sound quality.
More softwares may help you: Emicsoft Video Converter Emicsoft FLV Converter Emicsoft MTS Converter
!--removed tag-->hi all ,I have tried
but it does't work ,the message is : "-ERR Cannot connect to POP server 206.190.46.10 (206.190.46.10:110), connect error 10060\r\n"
anyone can help ??
thanks riry
//----------------------------------------------- private void button1_Click(object sender, EventArgs e) { try { Pop3 obj = new Pop3(); obj.Connect("pop3.yahoo.com", "myusername", "mypassword"); ArrayList list = obj.List(); foreach (Pop3Message msg in list) { Pop3Message msg2 = obj.Retrieve(msg); System.Console.WriteLine("Message {0}: {1}", msg2.number, msg2.message); } obj.Disconnect(); } catch (Pop3Exception ex) { MessageBox.Show(ex.Message); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
!--removed tag-->When i change the port to 587 from 110 i got the following error
220 mx.google.com ESMTP g14sm11215098rvb.54
!--removed tag-->Hi Got the following error when i try to call
obj.Connect("smtp.gmail.com", txtUser.Text, txtPass.Text);
A Connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host failed to respond 209.85.199.111: 110
Can any body please help me to fix this error?
!--removed tag-->Your code is too good. But in your code what happen If i send email today it display that email & tomarrow it show empty inbox. if i again send email it display that new mail only. And i also want to fetch Email subject,Email Body then what i do. Please give solution
!--removed tag-->