MailBee.NET Objects 4.0

Imap.Connect Method (String, Int32)

Connects to an IMAP4 server.

public bool Connect(
   string serverName,
   int port
);

Parameters

serverName
The name or IP address of the IMAP4 server.
port
The port on which to communicate with the server. The standard IMAP4 port is 143. For TLS/SSL connections, dedicated port is 993 (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.

Exceptions

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

Example

This sample connects to the IMAP4 server, logs in the account and selects "Inbox" folder, then 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.ImapMail;
using MailBee.Mime;

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

' The actual code (put it into a method of your class).
Dim imp As New Imap
imp.Connect("mail.domain.com", 143)
imp.Login("jdoe", "secret")
imp.SelectFolder("Inbox")
Dim msg As MailMessage = imp.DownloadEntireMessage(imp.MessageCount, False)
For Each attach As Attachment In msg.Attachments
    Console.WriteLine(attach.Filename)
Next
imp.Disconnect()

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.Connect Overload List