MailBee.NET Objects 3.1

Pop3.Connect Method (String, Int32)

Connects to a POP3 server.

public bool Connect(
   string serverName,
   int port
);

Parameters

serverName
The name or IP address of the POP3 server.
port
The port on which to communicate with the server. The standard POP3 port is 110. For TLS/SSL connections, dedicated port is 995 (however, TLS/SSL connections via regular port are possible too, see SslMode and StartTls topics).

Return Value

true if a connection attempt succeeded; otherwise, false.

Remarks

If Pipelining is true and the server supports pipelining, MailBee will use it and join POP3 commands in batches whenever possible (see Connect overload for more information).

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This sample connects to the POP3 server, downloads the last message entirely, and displays filenames of all attachments.

[C#]
// To use the code below, import MailBee namespaces at the top of your code
using MailBee;
using MailBee.Pop3Mail;
using MailBee.Mime;

// The actual code (put it into a method of your class)
Pop3 pop = new Pop3();
pop.Connect("mail.domain.com", 110);
pop.Login("jdoe", "secret");
MailMessage msg = pop.DownloadEntireMessage(pop.InboxMessageCount);
foreach (Attachment attach in msg.Attachments)
{
    Console.WriteLine(attach.Filename);
}
pop.Disconnect();
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code
Imports MailBee
Imports MailBee.Pop3Mail
Imports MailBee.Mime

' The actual code (put it into a method of your class)
Dim pop As New Pop3
pop.Connect("mail.domain.com", 110)
pop.Login("jdoe", "secret")
Dim msg As MailMessage
msg = pop.DownloadEntireMessage(pop.InboxMessageCount)
For Each attach As Attachment In msg.Attachments
    Console.WriteLine(attach.Filename)
Next
pop.Disconnect()

See Also

Pop3 Class | MailBee.Pop3Mail Namespace | Pop3.Connect Overload List