ImapConnect Method (String, Int32, Socket, EndPoint) |
Connects to an IMAP4 server.
Namespace: MailBee.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public bool Connect(
string serverName,
int port,
Socket socketToUse,
EndPoint localEndPoint
)
Public Function Connect (
serverName As String,
port As Integer,
socketToUse As Socket,
localEndPoint As EndPoint
) As Boolean
Parameters
- serverName
- Type: SystemString
The name or IP address of the IMAP4 server. - port
- 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). - socketToUse
- 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). - localEndPoint
- 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:
Booleantrue if a connection attempt succeeded; otherwise,
false.
Exceptions Remarks
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,
set
AutodetectPortAndSslMode to
false.
Examples 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).
using System.Net;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;
Imap imp = new Imap();
imp.Connect("mail.domain.com", 143, null, new IPEndPoint(IPAddress.Parse("192.168.0.123"), 3000));
imp.Disconnect();
Imports System.Net
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime
Dim imp As New Imap
imp.Connect("mail.domain.com", 143, Nothing, New IPEndPoint(IPAddress.Parse("192.168.0.123"), 3000))
imp.Disconnect()
See Also