SmtpAuthenticate
INT SmtpAuthenticate(
HCLIENT hClient,  
UINT nAuthType,  
LPCTSTR lpszUserName,  
LPCTSTR lpszPassword  
);

The SmtpAuthenticate function provides client authentication information to the server.

Parameters

hClient
The handle to the client session.
nAuthType
An integer value which specifies which method the library should use to authenticate the client session. This parameter should be set to one of the following values:
Constant
Description
SMTP_AUTH_DEFAULT The default authentication method will be used. This is effectively the same as specifying the SMTP_AUTH_LOGIN authentication method. If authentication is required, it is recommended that this value be used.
SMTP_AUTH_LOGIN The client will authenticate itself to the server using the AUTH LOGIN command. This requires that the server support the ESMTP protocol extensions and the AUTH command. The username and password strings must be specified and cannot be zero-length. Accounts with no set password are not supported using this authentication method.
lpszUserName
Pointer to a null-terminated string which specifies the account name for the user authorized to send mail through the server.
lpszPassword
Pointer to a null-terminated string which specifies the password for the user authorized to send mail through the server.

Return Value

If the function succeeds, the return value is the command result code. If the function fails, the return value is SMTP_ERROR. To get extended error information, call SmtpGetLastError.

Remarks

The SmtpAuthenticate function is used to authenticate the client to the mail server, which will enable it to deliver mail through the server. This requires that the server support the extended SMTP protocol and the AUTH LOGIN command.

Example

BOOL bExtended = TRUE; // Request use of extended options
DWORD dwOptions;
INT nResult;

// Determine if this server really does support extended
// options, and if it does, what they are

bExtended = SmtpGetExtendedOptions(hClient, &dwOptions);

if (bExtended && (dwOptions & SMTP_EXTOPT_AUTHLOGIN))
{
    nResult = SmtpAuthenticate(hClient, SMTP_AUTH_DEFAULT, lpszUserName, lpszPassword);
    if (nResult == SMTP_ERROR)
    {
        // An error occurred
        return;
    }
}

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

SmtpGetExtendedOptions


Copyright © 2008 Catalyst Development Corporation. All rights reserved.