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

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
public bool Connect(
	string serverName,
	int port,
	Socket socketToUse,
	EndPoint localEndPoint


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).
Type: System.Net.SocketsSocket
Usually, a null reference (Nothing in Visual Basic). You can supply your own socket object here if you wish MailBee to use this object instead of creating a new one (typically, to fine-tune the WinSock subsystem when you need to deal with thousands of connections).
Type: System.NetEndPoint
Usually, a null reference. Set it if you need to bind the connection to a certain local IP address/port to fine-tune the performance under heavy loads. If you supply your own socket object (via socketToUse argument), make sure you EITHER bind the local end point to this socket object in your own code (and pass a null reference as localEndPoint value) OR simply pass the local end point as localEndPoint value (not calling socket.Bind in your own code). Also, you can use no local end point at all. Just make sure you're not binding twice: directly in your code and via passing the local end point to this method.

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 using the specified local end point. This is useful if have multiple network adapters and wish to bind a particular connection to the specific adapter (you must know the IP address of this adapter).
// To use the code below, import these namespaces at the top of your code.
using System.Net;
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, null, new IPEndPoint(IPAddress.Parse(""), 3000));
See Also