|
BOOL Connect( |
|
LPCTSTR lpszHostName, |
|
|
UINT nRemotePort, |
|
|
UINT nTimeout, |
|
|
DWORD dwOptions |
|
); |
The Connect method is used to establish a connection with
the server.
Parameters
- lpszHostName
- A pointer to a null terminated string which specifies the host
name or IP address of the IMAP server.
- nRemotePort
- The port number the client should use to establish the
connection. A value of zero specifies that default port 143 should
be used, which is the standard port number assigned to the IMAP
service. If the secure port number is specified, an implicit
TLS connection will be established by default.
- nTimeout
- The number of seconds that the client will wait for a response
from the server before failing the current operation.
- dwOptions
- An unsigned integer value which specifies one or more options.
This parameter is constructed by using a bitwise operator with any
of the following values:
Value |
Description |
IMAP_OPTION_NONE |
No connection options specified. A standard connection to
the server will be established using the specified host name
and port number. |
IMAP_OPTION_IDENTIFY |
This option specifies the client should identify itself
to the server. If enabled, the client will send the ID command
to the server as defined in RFC 2971. This option has no effect
if the server does not support the ID command. |
IMAP_OPTION_TUNNEL |
This option specifies that a tunneled TCP connection and/or
port-forwarding is being used to establish the connection to
the server. This changes the behavior of the client with
regards to internal checks of the destination IP address and
remote port number, default capability selection and how the
connection is established. |
IMAP_OPTION_TRUSTEDSITE |
This option specifies the server is trusted. The
server certificate will not be validated and the connection
will always be permitted. This option only affects connections
using the TLS protocol. |
IMAP_OPTION_SECURE |
This option specifies that a secure connection should be
established with the server and requires that the server
support the TLS protocol. This option is the same
as specifying IMAP_OPTION_SECURE_EXPLICIT, which initiates the
secure session using the STARTTLS command. |
IMAP_OPTION_SECURE_EXPLICIT |
This option specifies the client should attempt to
establish a secure connection with the server. The server must
support secure connections using the TLS protocol
and the STARTTLS command. |
IMAP_OPTION_SECURE_IMPLICIT |
This option specifies the client should attempt to
establish a secure connection with the server. The server must
support secure connections using the TLS
protocol, and the secure session must be negotiated immediately
after the connection has been established. |
IMAP_OPTION_SECURE_FALLBACK |
This option specifies the client should permit the use
of less secure cipher suites for compatibility with legacy
servers. If this option is specified, the client will allow
connections using TLS 1.0 and cipher suites that use RC4, MD5
and SHA1. |
IMAP_OPTION_PREFER_IPV6 |
This option specifies the client should prefer the use of
IPv6 if the server hostname can be resolved to both an IPv6 and
IPv4 address. This option is ignored if the local system does
not have IPv6 enabled, or when the hostname can only be resolved
to an IPv4 address. If the server hostname can only be resolved
to an IPv6 address, the client will attempt to establish a
connection using IPv6 regardless if this option has been
specified. |
IMAP_OPTION_FREETHREAD |
This option specifies that this instance of the class may
be used by any thread, and is not limited to the thread which
created it. The application is responsible for ensuring that
access to the class instance is synchronized across multiple
threads. |
- hEventWnd
- The handle to the asynchronous notification window. This window
receives messages which notify the client of various asynchronous
client events that occur. Specifying this parameter and a message
identifier causes the connection to be non-blocking. If this
parameter is NULL, then a blocking connection is established.
- uEventMsg
- The message identifier that is used when an asynchronous client
event occurs. This value should be greater than WM_USER as defined
in the Windows header files. If the hEventWnd parameter is
NULL, this parameter should be specified as WM_NULL.
Return Value
If the method succeeds, the return value is non-zero. If the
method fails, the return value is zero. To get extended error
information, call GetLastError.
Remarks
This method will block the current thread until a connection has
been established or the timeout period has elapsed. To prevent it from
blocking the main user interface thread, the application should create
a background worker thread and establish a connection by calling the
Connect method in that thread. If the application
requires multiple simultaneous connections, it is recommended you
create a worker thread for each connection.
The dwOptions argument can be used to specify the threading
model that is used by the class when a connection is established. By
default, the client session is initially attached to the thread that
created it. From that point on, until the connection is terminated,
only the owner may invoke methods in that instance of the class. The
ownership of the class instance may be transferred from one thread to
another using the AttachThread method.
Specifying the IMAP_OPTION_FREETHREAD option enables any thread to
call methods in any instance of the class, regardless of which thread
created it. It is important to note that this option disables certain
internal safety checks which are performed by the class and may
result in unexpected behavior unless access to the class instance is
synchronized. If one thread calls a method in the class, it must
ensure that no other thread will call another method at the same time
using the same instance.
Requirements
Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: csmapv11.lib
Unicode: Implemented as Unicode and ANSI versions
See Also
Disconnect,
Login,
RegisterEvent,
SelectMailbox
|
|