SmtpConnect
HCLIENT SmtpConnect(
LPCTSTR lpszRemoteHost,  
UINT nRemotePort,  
UINT nTimeout,  
DWORD dwOptions,  
LPCTSTR lpszLocalName,  
LPSECURITYCREDENTIALS lpCredentials  
);

The SmtpConnect function is used to establish a connection with the remote server.

Parameters

lpszRemoteHost
A pointer to the name of the remote host to connect to; this may be a fully-qualified domain name, or an IP address.
nRemotePort
The port number the remote server is listening on. A value of zero specifies that the default port number should be used. For standard connections, the default port number is 25. For secure connections, the default port number is 465. If the secure port number is specified, an implicit SSL/TLS connection will be established by default.
nTimeout
The number of seconds that the client will wait for a response before failing the operation; a value of zero indicates that the client should wait an indefinite period of time.
dwOptions
A bitmask which specifies one or more options. This parameter is constructed by using a bitwise operator with any of the following values:
Constant
Description
SMTP_OPTION_EXTENDED Extended SMTP commands should be used if possible. This option enables features such as authentication and delivery status notification. If this option is not specified, the library will not attempt to use any extended features.
SMTP_OPTION_SECURE This option specifies that the client should attempt to establish a secure connection with the server. Note that the server must support secure connections using either the SSL or TLS protocol. This option is only available in the Secure Editions of SocketTools.
SMTP_OPTION_SECURE_IMPLICIT This option is used in addition to SMTP_OPTION_SECURE. It should be specified when the server expects an implicit SSL connection. This option should not be used with ESMTP servers that use the STARTTLS command to initiate a secure connection.
SMTP_OPTION_FREETHREAD This option specifies that the handle returned by this function 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 handle is synchronized across multiple threads.
lpszLocalName
A pointer to a null-terminated string which specifies the domain name of the local host. This parameter can be NULL or point to an empty string, in which case the local domain name is determined automatically from the system configuration. This parameter should be used if the mail server only accepts messages from a client that identifies itself using a specific domain name.
lpCredentials
A pointer to a SECURITYCREDENTIALS structure which is used to establish the client credentials for a secure connection to the remote server. The function SmtpCreateSecurityCredentials can be used to create this structure if necessary. If a standard non-secure connection is being established, or client credentials are not required by the server, this parameter can be NULL.

Remarks

The lpszLocalName argument should only point to a specific domain name if it is absolutely necessary. In most cases, it is preferable to pass this parameter as NULL or an empty string and allow the library to automatically determine the correct domain name to use. Providing an invalid domain name may cause the mail server to reject the connection.

The dwOptions argument can be used to specify the threading model that is used by the library when a connection is established. By default, the handle is initially attached to the thread that created it. From that point on, until the it is released, only the owner may call functions using that handle. The ownership of the handle may be transferred from one thread to another using the SmtpAttachThread function.

Specifying the SMTP_OPTION_FREETHREAD option enables any thread to call any function using the handle, regardless of which thread created it. It is important to note that this option disables certain internal safety checks which are performed by the library and may result in unexpected behavior unless access to the handle is synchronized. If one thread calls a function in the library, it must ensure that no other thread will call another function at the same time using the same handle.

Return Value

If the function succeeds, the return value is a handle to a client session. If the function fails, the return value is INVALID_CLIENT. To get extended error information, call SmtpGetLastError.

Requirements

Client: Requires Windows Vista, Windows XP or Windows 2000 Professional.
Server: Requires Windows Server 2008, Windows Server 2003 or Windows 2000 Server.
Header: Include cstools6.h.
Library: Use csmtpav6.lib.
Unicode: Implemented as Unicode and ANSI versions.

See Also

SmtpAsyncConnect, SmtpAuthenticate, SmtpDisconnect, SmtpInitialize, SmtpUninitialize


Copyright © 2008 Catalyst Development Corporation. All rights reserved.