|ImapConnect Method (String, Int32, Socket, EndPoint)|
Connects to an IMAP4 server.
MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public bool Connect(
Public Function Connect (
serverName As String,
port As Integer,
socketToUse As Socket,
localEndPoint As EndPoint
) As Boolean
- 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.
if a connection attempt succeeded; otherwise, false
By default, MailBee can autodetect if the mail server you're connecting to requires SSL connection (this works for
well-known mail services like gmail.com or live.com). Thus, this method can actually connect to the mail server on port 993 if you
specified "imap.gmail.com" as serverName
. To disable SSL mode and port autodetection,
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).
Imap imp = new Imap();
imp.Connect("mail.domain.com", 143, null, new IPEndPoint(IPAddress.Parse("192.168.0.123"), 3000));
Dim imp As New Imap
imp.Connect("mail.domain.com", 143, Nothing, New IPEndPoint(IPAddress.Parse("192.168.0.123"), 3000))