ComponentSoft.net Ultimate POP3 http://www.pop3component.net How to use POP3 Component in C#, VB.NET and ASP.NET posterous.com Thu, 10 Mar 2011 10:29:00 -0800 Deleting a message http://www.pop3component.net/deleting-a-message http://www.pop3component.net/deleting-a-message

Pop3Client class provides two methods Delete for deleting messages and Undelete for undeleting messages.

You use the Delete method to mark a message as deleted. It won't appear in subsequent message lists, but will actually only be removed from the mailbox after the session is disconnected using Disconnect method. You can recover messages that were marked as deleted by using the Undelete method.

The following steps will help you to delete a single message using the Delete method:

C#:

// POP3 server information. const string serverName = "myserver"; const string user = "name@domain.com"; const string password = "mytestpassword"; const int port = 995; const SecurityMode securityMode = SecurityMode.Implicit; // Create a new instance of the Pop3Client class. Pop3Client client = new Pop3Client(); // Connect to the server. client.Connect(serverName, port, securityMode); // Login to the server. client.Authenticate(user, password); // Delete a mail message with sequence number 1. client.Delete(1); // Close the connection. client.Disconnect();

VB.NET:

' POP3 server information. Const serverName As String = "myserver" Const user As String = "name@domain.com" Const password As String = "mytestpassword" Const port As Integer = 995 Const securityMode As SecurityMode = securityMode.Implicit ' Create a new instance of the Pop3Client class. Dim client As New Pop3Client() ' Connect to the server. client.Connect(serverName, port, securityMode) ' Login to the server. client.Authenticate(user, password) ' Delete a mail message with sequence number 1. client.Delete(1) ' Close the connection. client.Disconnect()

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net
Tue, 18 Jan 2011 20:07:00 -0800 POP3 Server with Explicit security mode http://www.pop3component.net/pop3-server-with-explicit-security-mode http://www.pop3component.net/pop3-server-with-explicit-security-mode

Explicit connection and Implicit connection are two secure methods to connect to a secure SMTP/POP3/POP3 server. This topic will go in detail the Explicit connection.

Explicit connection

When the client connects to the server using SSL, an SSL negotiation is initialized, the connection is secured and all following comminuation is being protected. 

The code snippet below shows how to connect to an POP3 server securely using Explicit security mode.

C#:

// Create a new instance of the Pop3Client class. Pop3Client client = new Pop3Client(); // Connect to the server. client.Connect("myserver", 143, SecurityMode.Explicit); // Login to the server. client.Authenticate("user", "password"); StringBuilder sb = new StringBuilder(); Pop3MessageCollection list = client.ListMessages(EnvelopeParts.Size | EnvelopeParts.UniqueId); for (int i = 0; i < list.Count; i++) {    sb.AppendFormat("{0} - {1}\r\n", i + 1, list[i].UniqueId); } Console.WriteLine(sb.ToString()); // Close the connection. client.Disconnect();

VB.NET:

<span>' Create a new instance of the Pop3Client class.</span> <span>Dim</span> client <span>As</span> <span>New</span> Pop3Client() <span>' Connect to the server.</span> client.Connect(<span>"myserver"</span>, 143, SecurityMode.<span>Explicit</span>) <span>' Login to the server.</span> client.Authenticate(<span>"user"</span>, <span>"password"</span>) <span>Dim</span> sb <span>As</span> <span>New</span> StringBuilder() <span>Dim</span> list <span>As</span> Pop3MessageCollection = client.ListMessages(EnvelopeParts.Size <span>Or</span> EnvelopeParts.UniqueId) <span>For</span> i <span>As</span> <span>Integer</span> = 0 <span>To</span> list.Count - 1     sb.AppendFormat(<span>"{0} - {1}"</span> & Constants.vbCrLf, i + 1, list(i).UniqueId) <span>Next</span> i Console.WriteLine(sb.ToString()) <span>' Close the connection.</span> client.Disconnect()

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net
Sun, 19 Sep 2010 10:35:00 -0700 Handling Bounced Message on a POP3 Account with Ultimate Bounce Inspector http://www.pop3component.net/handling-bounced-message-on-a-pop3-account-wi http://www.pop3component.net/handling-bounced-message-on-a-pop3-account-wi
You can download and process messages from either IMAP server or POP3 server easily with Ultimate Bounce Inspector component. To download and process messages from a POP3 server, you can use the following code:

Downloading and processing multiple EML files from a POP3 server

  1. Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
    C#  
    using ComponentSoft.Net.Mail;
    VB.NET  
    Imports ComponentSoft.Net.Mail
  2. Create a new instance of the Pop3Client class.
  3. Connect to the POP3 server with the Connect methods and authenticate the user with the Authenticate method. The code looks similar to the following:
    C#  
    // POP3 server information.
    const string serverName = "myserver";
    const string user = "name@domain.com";
    const string password = "mytestpassword";
    const int port = 995;
    const SecurityMode securityMode = SecurityMode.Implicit;
    // Create a new instance of the Pop3Client class.
    Pop3Client client = new Pop3Client();
    Console.WriteLine(
    "Connecting Pop3 server: {0}:{1}...", serverName, port);
    // Connect to the server.
    client.Connect(serverName, port, securityMode);
    // Login to the server.
    Console.WriteLine("Logging in as {0}...", user);
    client.Authenticate(user, password);
    VB.NET  
    ' POP3 server information.
    Const serverName As String = "myserver"
    Const user As String = "name@domain.com"
    Const password As String = "mytestpassword"
    Const port As Integer = 995
    Const securityMode As SecurityMode = securityMode.Implicit
    ' Create a new instance of the Pop3Client class.
    Dim client As New Pop3Client()
    Console.WriteLine("Connecting Pop3 server: {0}:{1}...", serverName, port)
    ' Connect to the server.
    client.Connect(serverName, port, securityMode)
    ' Login to the server.
    Console.WriteLine("Logging in as {0}...", user)
    client.Authenticate(user, password)
  4. Create a new instance of the BounceInspector class.
    C#  
    // Create a new instance of the BounceInspector class.
    BounceInspector inspector = new BounceInspector();
    VB.NET  
    ' Create a new instance of the BounceInspector class.
    Dim inspector As New BounceInspector()
  5. Now pass the newly created instance of the Pop3Client class and optional destination path that is used to store downloaded EML files to the ProcessMessages method. The code looks similar to the following:
    C#  
    // Download messages from Pop3 Inbox to 'c:\test' and process them.
    BounceResultCollection result = inspector.ProcessMessages(client, "c:\\test");
    VB.NET  
    ' Download messages from Pop3 Inbox to 'c:\test' and process them.
    Dim result As BounceResultCollection = inspector.ProcessMessages(client, "c:\test")
  6. After completing your work, call the Disconnect method to close the POP3 session.

Final example code

C#  
// POP3 server information.
const string serverName = "myserver";
const string user = "name@domain.com";
const string password = "mytestpassword";
const int port = 995;
const SecurityMode securityMode = SecurityMode.Implicit;
// Create a new instance of the Pop3Client class.
Pop3Client client = new Pop3Client();
Console.WriteLine(
"Connecting Pop3 server: {0}:{1}...", serverName, port);
// Connect to the server.
client.Connect(serverName, port, securityMode);
// Login to the server.
Console.WriteLine("Logging in as {0}...", user);
client.Authenticate(user, password);
// Initialize BounceInspector.
BounceInspector inspector = new BounceInspector();
inspector.AllowInboxDelete = false;
// true if you want BounceInspector automatically delete all hard bounces.
// Register processed event handler.
inspector.Processed += inspector_Processed;
// Download messages from Pop3 Inbox to 'c:\test' and process them.
BounceResultCollection result = inspector.ProcessMessages(client, "c:\\test");
// Display processed emails.
foreach (BounceResult r in result)
{
   
// If this message was identified as a bounced email message.
   
if (r.Identified)
   {
       
// Print out the result
       
Console.Write("FileName: {0}\nSubject: {1}\nAddress: {2}\nBounce Category: {3}\nBounce Type: {4}\nDeleted: {5}\nDSN Action: {6}\nDSN Diagnostic Code: {7}\n\n",
                       System.IO.Path.GetFileName(r.FilePath),
                       r.MailMessage.Subject,
                       r.Addresses[0],
                       r.BounceCategory.Name,
                       r.BounceType.Name,
                       r.FileDeleted,
                       r.Dsn.Action,
                       r.Dsn.DiagnosticCode);
   }
}
Console.WriteLine(
"{0} bounced message found", result.BounceCount);
// Disconnect.
Console.WriteLine("Disconnecting...");
client.Disconnect();

VB.NET  
' POP3 server information.
Const serverName As String = "myserver"
Const user As String = "name@domain.com"
Const password As String = "mytestpassword"
Const port As Integer = 995
Const securityMode As SecurityMode = securityMode.Implicit
' Create a new instance of the Pop3Client class.
Dim client As New Pop3Client()
Console.WriteLine("Connecting Pop3 server: {0}:{1}...", serverName, port)
' Connect to the server.
client.Connect(serverName, port, securityMode)
' Login to the server.
Console.WriteLine("Logging in as {0}...", user)
client.Authenticate(user, password)
' Initialize BounceInspector.
Dim inspector As New BounceInspector()
inspector.AllowInboxDelete = False ' true if you want BounceInspector automatically delete all hard bounces.
' Register processed event handler.
AddHandler inspector.Processed, AddressOf inspector_Processed
' Download messages from Pop3 Inbox to 'c:\test' and process them.
Dim result As BounceResultCollection = inspector.ProcessMessages(client, "c:\test")
' Display processed emails.
For Each r As BounceResult In result
    ' If this message was identified as a bounced email message.
    If r.Identified Then
        ' Print out the result
        Console.Write("FileName: {0}" & Constants.vbLf & "Subject: {1}" & Constants.vbLf & "Address: {2}" & Constants.vbLf & "Bounce Category: {3}" & Constants.vbLf & "Bounce Type: {4}" & Constants.vbLf & "Deleted: {5}" & Constants.vbLf & "DSN Action: {6}" & Constants.vbLf & "DSN Diagnostic Code: {7}" & Constants.vbLf + Constants.vbLf, System.IO.Path.GetFileName(r.FilePath), r.MailMessage.Subject, r.Addresses(0), r.BounceCategory.Name, r.BounceType.Name, r.FileDeleted, r.Dsn.Action, r.Dsn.DiagnosticCode)
    End If
Next r
Console.WriteLine("{0} bounced message found", result.BounceCount)
' Disconnect.
Console.WriteLine("Disconnecting...")
client.Disconnect()

 

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net
Tue, 22 Jun 2010 20:10:00 -0700 How to List Messages http://www.pop3component.net/how-to-list-messages http://www.pop3component.net/how-to-list-messages

Both ImapClient and Pop3Client allow you to retrieve a list of messages on the server with methods named ListMessages.With the Pop3Client, you can pass an optional flag parameter indicating which part of the message will be retrieved. The ListMessages method returns a collection of Pop3Message object containing information about messages you have requested as shown the following steps:

  • Add using directives to your code to create aliases for existing root namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:

    C#

    using ComponentSoft.Net.Mail;

    VB.NET

    Imports ComponentSoft.Net.Mail

  • Create a new instance of the Pop3Client class and connect to the POP3 server with Connect methods. The code looks similar to the following:
    C#

    // Create a new instance of the Pop3Client class.
    Pop3Client client = new Pop3Client();
    // Connect to the server.
    client.Connect("myserver");
    // Or you can specify the POP3 port with
    // client.Connect("myserver", 110);
    // Login to the server.
    client.Authenticate("user", "password");
    // List messages. Only Size and UniqueId are retrieved.
    Pop3MessageCollection list = client.ListMessages(EnvelopeParts.Size | EnvelopeParts.UniqueId);
    foreach (Pop3Message m in list)
    {
       Console.WriteLine(
    string.Format("UniqueId: {0}, Size: {1}", m.UniqueId, m.Size));
    }
    // Close the connection.
    client.Disconnect();

    VB.NET

    ' Create a new instance of the Pop3Client class.
    Dim client As New Pop3Client()
    ' Connect to the server.
    client.Connect("myserver")
    ' Or you can specify the POP3 port with
    ' client.Connect("myserver", 110);
    ' Login to the server.
    client.Authenticate("user""password")
    ' List messages. Only Size and UniqueId are retrieved.
    Dim list As Pop3MessageCollection = client.ListMessages(EnvelopeParts.Size OrEnvelopeParts.UniqueId)
    For Each m As Pop3Message In list
        Console.WriteLine(String.Format("UniqueId: {0}, Size: {1}", m.UniqueId, m.Size))
    Next m
    ' Close the connection.
    client.Disconnect()

  • Permalink | Leave a comment  »

    ]]>
    http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net
    Sat, 19 Jun 2010 14:23:00 -0700 How to obtain mailbox information http://www.pop3component.net/how-to-obtain-mailbox-information http://www.pop3component.net/how-to-obtain-mailbox-information

    The simplest way to obtain information about a specified mailbox is using GetMailboxInfo method. You only need to pass the mailbox name to the method. It returns a Pop3MailboxInfo object containing information about the mailbox you have requested.

    The following steps will help you to do that using ComponentSoft Mail component:

    C#

    // Create a new instance of the Pop3Client class. Pop3Client client = new Pop3Client(); // Connect to the server. client.Connect("myserver"); // Or you can specify the POP3 port with // client.Connect("myserver", 110); // Login to the server. client.Authenticate("user", "password"); // Obtain mailbox information. Pop3MailboxInfo info = client.GetMailboxInfo(); // Print out some information. Console.WriteLine("Number of messages found: {0}", info.MessageCount); Console.WriteLine("Mailbox Size: {0}", info.Size); // Close the connection. client.Disconnect();

    VB.NET

    ' Create a new instance of the Pop3Client class. Dim client As New Pop3Client() ' Connect to the server. client.Connect("myserver") ' Or you can specify the POP3 port with ' client.Connect("myserver", 110); ' Login to the server. client.Authenticate("user", "password") ' Obtain mailbox information. Dim info As Pop3MailboxInfo = client.GetMailboxInfo() ' Print out some information. Console.WriteLine("Number of messages found: {0}", info.MessageCount) Console.WriteLine("Mailbox Size: {0}", info.Size) ' Close the connection. client.Disconnect()

    Permalink | Leave a comment  »

    ]]>
    http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net