| Ferrysoft | POP3 Module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home Products Support Development Contact | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
POP3 Module Overview The Ferrysoft POP3 Module is a Post Office Protocol (POP3) client class to interrogate a POP3 server for available emails, download the emails and return them to the calling program. The POP3 Module is provided in source code form (Visual Basic 2005/2008 compatible and Visual C# 2005/2008 compatible). It is intended for developers, to incorporate into their own applications, in order to provide POP3 client support to the application. The module can be used, royalty-free, by any individual or organisation that purchases the module. As the module is provided in source code form, it can be modified as necessary after purchase, provided that any derived module is not distributed, in source code form, to a third party. The module can be incorporated into a commercial product and sold to third parties, in compiled format, provided that the purpose of the commercial product is not simply to act as a wrapper for the POP3 Module. Buy It
The POP3 Module is priced in Pounds Sterling (GBP), US Dollars (USD) and Euros (EUR).
Summary The Ferrysoft POP3 Module provides the capability to interrogate a POP3 server for available emails, download the emails and return them to the calling program. Summary of methods provided by the class The methods provided by the class are described in the following table.
Summary of properties provided by the class The properties provided by the class are described in the following table.
Capability method Syntax Visual Basic
Public Sub Capability()
C#
public void Capability()
Close method Syntax Visual Basic
Public Sub Close()
C#
public void Close()
DeleteMessage method Syntax Visual Basic Public Sub DeleteMessage( _ ByVal MessageNumber As Integer) C# public void DeleteMessage( int MessageNumber) Parameters
GetMailboxStatus method Syntax Visual Basic
Public Sub GetMailboxStatus()
C#
public void GetMailboxStatus()
GetMessage method Syntax Visual Basic Public Sub GetMessage( _ ByVal MessageNumber As Integer) C# public void GetMessage( int MessageNumber) Parameters
GetMessageHeader method Syntax Visual Basic Public Sub GetMessageHeader( _ ByVal MessageNumber As Integer) C# public void GetMessageHeader( int MessageNumber) Parameters
KeepAlive method Syntax Visual Basic
Public Sub KeepAlive()
C#
public void KeepAlive()
Open method Syntax Visual Basic Public Sub Open( _ ByVal Pop3Server As String, _ ByVal Pop3Port As Integer, _ ByVal Pop3Encrypted As Boolean, _ ByVal Pop3Username As String, _ ByVal Pop3Password As String) C# public void Open( string Pop3Server, int Pop3Port, bool Pop3Encrypted, string Pop3Username, string Pop3Password) Parameters
RollbackDeletes method Syntax Visual Basic
Public Sub RollbackDeletes()
C#
public void RollbackDeletes()
AlternateViews property Syntax Visual Basic Public ReadOnly Property AlternateViews As System.Collections.ArrayList C# public System.Collections.ArrayList AlternateViews { get; } Using the AlternateViews property Get the collection of alternate views for the most recently retrieved message. A multipart message may contain text parts in alternate formats (for example text/plain or text/html). If the message is not multipart then the message text is contained in the first and only alternate view. Each text part is contained in an alternate view class. Each alternate view class contains Content, ContentType (MediaType and CharSet) and ContentTransferEncoding (Mechanism). Attachments property Syntax Visual Basic Public ReadOnly Property Attachments As System.Collections.ArrayList C# public System.Collections.ArrayList Attachments { get; } Using the Attachments property Get the collection of attachments for the most recently retrieved message. Each attachment is contained in an attachment class. Each attachment class contains Content, ContentSize, ContentType (MediaType and CharSet), ContentTransferEncoding (Mechanism) and ContentDisposition (DispositionType, FileName, Size, CreationDate, ModificationDate and ReadDate). LastCommandSent property Syntax Visual Basic Public ReadOnly Property LastCommandSent As String C# public string LastCommandSent { get; } Using the LastCommandSent property Get the last command sent to the server. LastResponseOK property Syntax Visual Basic Public ReadOnly Property LastResponseOK As Boolean C# public bool LastResponseOK { get; } Using the LastResponseOK property Get a true/false indicator of whether the last response from the server was an OK response. LastResponseReceived property Syntax Visual Basic Public ReadOnly Property LastResponseReceived As String C# public string LastResponseReceived { get; } Using the LastResponseReceived property Get the last response received from the server. MailboxSize property Syntax Visual Basic Public ReadOnly Property MailboxSize As Long C# public long MailboxSize { get; } Using the MailboxSize property Get the size (number of octets) for the most recently opened mailbox. MessageCount property Syntax Visual Basic Public ReadOnly Property MessageCount As Integer C# public int MessageCount { get; } Using the MessageCount property Get the number of messages for the most recently opened mailbox. MessageHeaders property Syntax Visual Basic Public ReadOnly Property MessageHeaders _ As System.Collections.Generic.Dictionary(Of Integer, String) C# public System.Collections.Generic.Dictionary<int, string> MessageHeaders { get; } Using the MessageHeaders property
MessageSize property Syntax Visual Basic Public ReadOnly Property MessageSize As Integer C# public int MessageSize { get; } Using the MessageSize property Get the size (number of octets) for the most recently retrieved message. State property Syntax Visual Basic Public ReadOnly Property State As Ferrysoft.Pop3.ConnectionState C# public Ferrysoft.Pop3.ConnectionState State { get; } Using the State property
Example Use The code below shows an example of how to use the POP3 client class. Visual Basic ' ' This example uses the POP3 object to connect ' to a POP3 server and process any messages ' waiting in the mailbox. For each message, ' the message headers, alternate views and ' attachments are shown. ' Dim Pop3Client As Ferrysoft.Pop3.Client Dim Pop3Server As String Dim Pop3Port As Integer Dim Pop3Encrypted As Boolean Dim Pop3Username As String Dim Pop3Password As String Dim MailboxSize As Long = 0 Dim MessageCount As Integer = 0 Dim MessageSize As Integer = 0 Pop3Client = New Ferrysoft.Pop3.Client() ' ' Set the Server, Username, Password ' and Encrypted to the credentials needed ' in order to connect to your POP3 mailbox. ' Port is defaulted according to the ' setting of Encrypted. ' Port can be overridden if a non-standard ' port is required to access your POP3 mailbox. ' Pop3Server = "pop.example.com" Pop3Username = "myusername" Pop3Password = "mypassword" Pop3Encrypted = True If Pop3Encrypted Then Pop3Port = 995 Else Pop3Port = 110 End If Try WriteLineString("Init started") Pop3Client.Open( _ Pop3Server, _ Pop3Port, _ Pop3Encrypted, _ Pop3Username, _ Pop3Password) If Pop3Client.LastResponseOK Then WriteLineSent(Pop3Client) WriteLineReceived(Pop3Client) MessageCount = Pop3Client.MessageCount MailboxSize = Pop3Client.MailboxSize WriteLineValue("Message Count", MessageCount) WriteLineValue("Mailbox Size", MailboxSize) Else WriteLineString("Open failed") WriteLineSent(Pop3Client) WriteLineReceived(Pop3Client) End If WriteLineString("Init finished") Catch WriteLineString("EXCEPTION") End Try If MessageCount <> 0 Then Try For MessageNumber = 1 To MessageCount Pop3Client.GetMessage(MessageNumber) If Pop3Client.LastResponseOK Then WriteLineSent(Pop3Client) WriteLineOK(Pop3Client) MessageSize = Pop3Client.MessageSize WriteLineValue("Message Size", MessageSize) WriteLineMessageHeadersStyleA(Pop3Client) WriteLineMessageHeadersStyleB(Pop3Client) WriteLineMessageHeadersStyleC(Pop3Client) WriteLineAlternateViews(Pop3Client) WriteLineAttachments(Pop3Client) Else WriteLineString("GetMessage failed") WriteLineSent(Pop3Client) WriteLineReceived(Pop3Client) End If Next Catch WriteLineString("EXCEPTION") End Try End If Try WriteLineString("Term started") If Pop3Client.State <> Ferrysoft.Pop3.ConnectionState.Closed Then Pop3Client.Close() WriteLineSent(Pop3Client) WriteLineReceived(Pop3Client) End If WriteLineString("Term finished") Catch WriteLineString("EXCEPTION") End Try Private Sub WriteLineMessageHeadersStyleA( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the message headers. ' This style processes each of the members of the collection. ' WriteLineString("Message Header Style A ...") For Each KeyValuePair _ As System.Collections.Generic.KeyValuePair(Of Integer, String) _ In Pop3Client.MessageHeaders() If KeyValuePair.Value.Length <> 0 Then System.Console.WriteLine("Key={0} Value={1}", _ KeyValuePair.Key, KeyValuePair.Value) End If Next WriteLineString("End Message Header") End Sub Private Sub WriteLineMessageHeadersStyleB( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the message headers. ' This style processes each of the members of the enumeration ' MessageHeaderType to obtain the values and names for use in ' processing each of the members of the collection. ' WriteLineString("Message Header Style B ...") For Each Mht As Ferrysoft.Pop3.MessageHeaderType In _ Ferrysoft.Pop3.MessageHeaderType.GetValues( _ GetType(Ferrysoft.Pop3.MessageHeaderType)) Dim Mhv As String = Pop3Client.MessageHeaders(Mht) If Mhv.Length <> 0 Then Dim Mhn As String = Ferrysoft.Pop3.MessageHeaderType.GetName( _ GetType(Ferrysoft.Pop3.MessageHeaderType), Mht) System.Console.WriteLine("{0}: {1}", Mhn, Mhv) End If Next WriteLineString("End Message Header") End Sub Private Sub WriteLineMessageHeadersStyleC( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the message headers. ' This style processes a sample set of specific members of the collection. ' WriteLineString("Message Header Style C ...") System.Console.WriteLine("{0}: {1}", "Subject", _ Pop3Client.MessageHeaders(Ferrysoft.Pop3.MessageHeaderType.Subject)) System.Console.WriteLine("{0}: {1}", "From", _ Pop3Client.MessageHeaders(Ferrysoft.Pop3.MessageHeaderType.From)) System.Console.WriteLine("{0}: {1}", "To", _ Pop3Client.MessageHeaders(Ferrysoft.Pop3.MessageHeaderType.To)) WriteLineString("End Message Header") End Sub Private Sub WriteLineAlternateViews( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the alternate views. ' WriteLineString("AlternateViews ...") For Each AlternateView As Ferrysoft.Pop3.AlternateView _ In Pop3Client.AlternateViews WriteLineAlternateView(AlternateView) Next WriteLineString("End AlternateViews") End Sub Private Sub WriteLineAttachments( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the attachments. ' WriteLineString("Attachments ...") For Each Attachment As Ferrysoft.Pop3.Attachment _ In Pop3Client.Attachments WriteLineAttachment(Attachment) Next WriteLineString("End Attachments") End Sub Private Sub WriteLineAlternateView( _ ByVal AlternateView As Ferrysoft.Pop3.AlternateView) ' ' Show the alternate view. ' WriteLineString("AlternateView ...") WriteLineString(AlternateView.ContentType.ToString()) WriteLineString(AlternateView.ContentTransferEncoding.ToString()) WriteLineString(AlternateView.Content) WriteLineString("End AlternateView") End Sub Private Sub WriteLineAttachment( _ ByVal Attachment As Ferrysoft.Pop3.Attachment) ' ' Show the attachment. ' WriteLineString("Attachment ...") WriteLineString(Attachment.ContentType.ToString()) WriteLineString(Attachment.ContentTransferEncoding.ToString()) WriteLineString(Attachment.ContentDisposition.ToString()) WriteLineString("End Attachment") End Sub Private Sub WriteLineSent( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the last command sent from the client to the server. ' System.Console.WriteLine("Client: {0}", Pop3Client.LastCommandSent) End Sub Private Sub WriteLineReceived( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the last response received from the server by the client. ' System.Console.WriteLine("Server: {0}", Pop3Client.LastResponseReceived) End Sub Private Sub WriteLineOK( _ ByVal Pop3Client As Ferrysoft.Pop3.Client) ' ' Show the OK or ERR response received from the server by the client. ' If Pop3Client.LastResponseOK Then WriteLineString("Server: +OK") Else WriteLineString("Server: -ERR") End If End Sub Private Sub WriteLineValue( _ ByVal NameString As String, _ ByVal ValueLong As Long) ' ' Show a name value pair. ' System.Console.WriteLine("{0}: {1:0}", NameString, ValueLong) End Sub Private Sub WriteLineString( _ ByVal ValueString As String) ' ' Show a string. ' System.Console.WriteLine(ValueString) End Sub C# // // This example uses the POP3 object to connect // to a POP3 server and process any messages // waiting in the mailbox. For each message, // the message headers, alternate views and // attachments are shown. // Ferrysoft.Pop3.Client Pop3Client; string Pop3Server; int Pop3Port; bool Pop3Encrypted; string Pop3Username; string Pop3Password; long MailboxSize = 0; int MessageCount = 0; int MessageSize = 0; Pop3Client = new Ferrysoft.Pop3.Client(); // // Set the Server, Username, Password // and Encrypted to the credentials needed // in order to connect to your POP3 mailbox. // Port is defaulted according to the // setting of Encrypted. // Port can be overridden if a non-standard // port is required to access your POP3 mailbox. // Pop3Server = "pop.example.com"; Pop3Username = "myusername"; Pop3Password = "mypassword"; Pop3Encrypted = true; if (Pop3Encrypted) Pop3Port = 995; else Pop3Port = 110; try { WriteLineString("Init started"); Pop3Client.Open( Pop3Server, Pop3Port, Pop3Encrypted, Pop3Username, Pop3Password); if (Pop3Client.LastResponseOK) { WriteLineSent(Pop3Client); WriteLineReceived(Pop3Client); MessageCount = Pop3Client.MessageCount; MailboxSize = Pop3Client.MailboxSize; WriteLineValue("Message Count", MessageCount); WriteLineValue("Mailbox Size", MailboxSize); } else { WriteLineString("Open failed"); WriteLineSent(Pop3Client); WriteLineReceived(Pop3Client); } WriteLineString("Init finished"); } catch { WriteLineString("EXCEPTION"); } if (MessageCount != 0) { try { for (int MessageNumber = 1; MessageNumber <= MessageCount; MessageNumber++) { Pop3Client.GetMessage(MessageNumber); if (Pop3Client.LastResponseOK) { WriteLineSent(Pop3Client); WriteLineOK(Pop3Client); MessageSize = Pop3Client.MessageSize; WriteLineValue("Message Size", MessageSize); WriteLineMessageHeadersStyleA(Pop3Client); WriteLineMessageHeadersStyleB(Pop3Client); WriteLineMessageHeadersStyleC(Pop3Client); WriteLineAlternateViews(Pop3Client); WriteLineAttachments(Pop3Client); } else { WriteLineString("GetMessage failed"); WriteLineSent(Pop3Client); WriteLineReceived(Pop3Client); } } } catch { WriteLineString("EXCEPTION"); } } try { WriteLineString("Term started"); if (Pop3Client.State != Ferrysoft.Pop3.ConnectionState.Closed) { Pop3Client.Close(); WriteLineSent(Pop3Client); WriteLineReceived(Pop3Client); } WriteLineString("Term finished"); } catch { WriteLineString("EXCEPTION"); } private static void WriteLineMessageHeadersStyleA( Ferrysoft.Pop3.Client Pop3Client) { // // Show the message headers. // This style processes each of the members of the collection. // WriteLineString("Message Header Style A ..."); foreach (System.Collections.Generic.KeyValuePair<int, string> KeyValuePair in Pop3Client.MessageHeaders) { if (KeyValuePair.Value.Length != 0) System.Console.WriteLine("Key={0} Value={1}", KeyValuePair.Key, KeyValuePair.Value); } WriteLineString("End Message Header"); } private static void WriteLineMessageHeadersStyleB( Ferrysoft.Pop3.Client Pop3Client) { // // Show the message headers. // This style processes each of the members of the enumeration // MessageHeaderType to obtain the values and names for use in // processing each of the members of the collection. // WriteLineString("Message Header Style B ..."); foreach (Ferrysoft.Pop3.MessageHeaderType Mht in Ferrysoft.Pop3.MessageHeaderType.GetValues( typeof(Ferrysoft.Pop3.MessageHeaderType))) { string Mhv = Pop3Client.MessageHeaders[(int)Mht]; if (Mhv.Length != 0) { string Mhn = Ferrysoft.Pop3.MessageHeaderType.GetName( typeof(Ferrysoft.Pop3.MessageHeaderType), Mht); System.Console.WriteLine("{0}: {1}", Mhn, Mhv); } } WriteLineString("End Message Header"); } private static void WriteLineMessageHeadersStyleC( Ferrysoft.Pop3.Client Pop3Client) { // // Show the message headers. // This style processes a sample set of specific members of the collection. // WriteLineString("Message Header Style C ..."); System.Console.WriteLine("{0}: {1}", "Subject", Pop3Client.MessageHeaders[(int)Ferrysoft.Pop3.MessageHeaderType.Subject]); System.Console.WriteLine("{0}: {1}", "From", Pop3Client.MessageHeaders[(int)Ferrysoft.Pop3.MessageHeaderType.From]); System.Console.WriteLine("{0}: {1}", "To", Pop3Client.MessageHeaders[(int)Ferrysoft.Pop3.MessageHeaderType.To]); WriteLineString("End Message Header"); } private static void WriteLineAlternateViews( Ferrysoft.Pop3.Client Pop3Client) { // // Show the alternate views. // WriteLineString("AlternateViews ..."); foreach (Ferrysoft.Pop3.AlternateView AlternateView in Pop3Client.AlternateViews) { WriteLineAlternateView(AlternateView); } WriteLineString("End AlternateViews"); } private static void WriteLineAttachments( Ferrysoft.Pop3.Client Pop3Client) { // // Show the attachments. // WriteLineString("Attachments ..."); foreach (Ferrysoft.Pop3.Attachment Attachment in Pop3Client.Attachments) { WriteLineAttachment(Attachment); } WriteLineString("End Attachments"); } private static void WriteLineAlternateView( Ferrysoft.Pop3.AlternateView AlternateView) { // // Show the alternate view. // WriteLineString("AlternateView ..."); WriteLineString(AlternateView.ContentType.ToString()); WriteLineString(AlternateView.ContentTransferEncoding.ToString()); WriteLineString(AlternateView.Content); WriteLineString("End AlternateView"); } private static void WriteLineAttachment( Ferrysoft.Pop3.Attachment Attachment) { // // Show the attachment. // WriteLineString("Attachment ..."); WriteLineString(Attachment.ContentType.ToString()); WriteLineString(Attachment.ContentTransferEncoding.ToString()); WriteLineString(Attachment.ContentDisposition.ToString()); WriteLineString("End Attachment"); } private static void WriteLineSent( Ferrysoft.Pop3.Client Pop3Client) { // // Show the last command sent from the client to the server. // System.Console.WriteLine("Client: {0}", Pop3Client.LastCommandSent); } private static void WriteLineReceived( Ferrysoft.Pop3.Client Pop3Client) { // // Show the last response received from the server by the client. // System.Console.WriteLine("Server: {0}", Pop3Client.LastResponseReceived); } private static void WriteLineOK( Ferrysoft.Pop3.Client Pop3Client) { // // Show the OK or ERR response received from the server by the client. // if (Pop3Client.LastResponseOK) WriteLineString("Server: +OK"); else WriteLineString("Server: -ERR"); } private static void WriteLineValue( string NameString, long ValueLong) { // // Show a name value pair. // System.Console.WriteLine("{0}: {1:0}", NameString, ValueLong); } private static void WriteLineString( string ValueString) { // // Show a string. // System.Console.WriteLine(ValueString); } In the example below, the above code is run against a POP3 server with two messages waiting in the user's mailbox. It produces the following output: Init started Client: STAT Server: +OK 2 4852 Message Count: 2 Mailbox Size: 4852 Init finished Client: RETR 1 Server: +OK Message Size: 2421 Message Header Style A ... Key=11 Value=7bit Key=12 Value=text/plain; charset="us-ascii" Key=14 Value=us-ascii Key=15 Value=text/plain Key=16 Value=Wed, 7 Oct 2009 17:17:04 +0100 Key=17 Value="John Doe" <john.doe@example.com> Key=18 Value=john.doe@example.com Key=20 Value=<000b01ca4769$9c678a90$d5369fb0$@doe@example.com> Key=21 Value=1.0 Key=25 Value=Test Message A Key=26 Value=<jane.doe@example.com> End Message Header Message Header Style B ... ContentTransferEncoding: 7bit ContentType: text/plain; charset="us-ascii" ContentTypeCharSet: us-ascii ContentTypeMediaType: text/plain Date: Wed, 7 Oct 2009 17:17:04 +0100 From: "John Doe" <john.doe@example.com> FromEmailAddress: john.doe@example.com MessageID: <000b01ca4769$9c678a90$d5369fb0$@doe@example.com> MIMEVersion: 1.0 Subject: Test Message A To: <jane.doe@example.com> End Message Header Message Header Style C ... Subject: Test Message A From: "John Doe" <john.doe@example.com> To: <jane.doe@example.com> End Message Header AlternateViews ... AlternateView ... Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This is test message A. It is a single-part plain text message. End AlternateView End AlternateViews Attachments ... End Attachments Client: RETR 2 Server: +OK Message Size: 2431 Message Header Style A ... Key=11 Value=7bit Key=12 Value=text/plain; charset="us-ascii" Key=14 Value=us-ascii Key=15 Value=text/plain Key=16 Value=Wed, 7 Oct 2009 17:17:16 +0100 Key=17 Value="John Doe" <john.doe@example.com> Key=18 Value=john.doe@example.com Key=20 Value=<000c01ca4769$a32aa6a0$e97ff3e0$@doe@example.com> Key=21 Value=1.0 Key=25 Value=Test Message B Key=26 Value=<jane.doe@example.com> End Message Header Message Header Style B ... ContentTransferEncoding: 7bit ContentType: text/plain; charset="us-ascii" ContentTypeCharSet: us-ascii ContentTypeMediaType: text/plain Date: Wed, 7 Oct 2009 17:17:16 +0100 From: "John Doe" <john.doe@example.com> FromEmailAddress: john.doe@example.com MessageID: <000c01ca4769$a32aa6a0$e97ff3e0$@doe@example.com> MIMEVersion: 1.0 Subject: Test Message B To: <jane.doe@example.com> End Message Header Message Header Style C ... Subject: Test Message B From: "John Doe" <john.doe@example.com> To: <jane.doe@example.com> End Message Header AlternateViews ... AlternateView ... Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This is test message B. It is a single-part plain text message. End AlternateView End AlternateViews Attachments ... End Attachments Term started Client: QUIT Server: +OK Farewell. Term finished |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 2004-2010 Ferrysoft Limited. All rights reserved. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||