ImapConnect Method (String, Int32)
Connects to an IMAP4 server.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public bool Connect(
	string serverName,
	int port


Type: SystemString
The name or IP address of the IMAP4 server.
Type: SystemInt32
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

Type: Boolean
true if a connection attempt succeeded; otherwise, false.
MailBeeExceptionAn error occurred and ThrowExceptions is true.
By default, MailBee can autodetect if the mail server you're connecting to requires SSL connection (this works for well-known mail services like or Thus, this method can actually connect to the mail server on port 993 if you specified "" as serverName. To disable SSL mode and port autodetection, set AutodetectPortAndSslMode to false.
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.
// 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("", 143);
imp.Login("jdoe", "secret");
MailMessage msg = imp.DownloadEntireMessage(imp.MessageCount, false);
foreach (Attachment attach in msg.Attachments)
See Also