Connect Method  
 

Establish a connection with a server.

Syntax

object.Connect( [RemoteHost], [RemotePort], [UserName], [Password], [Timeout], [Options] )

Parameters

RemoteHost
A string which specifies the host name or IP address of the server. If this argument is not specified, it defaults to the value of the HostAddress property if it is defined. Otherwise, it defaults to the value of the HostName property.
RemotePort
A number which specifies the port to connect to on the server. If this argument is not specified, it defaults to the value of the RemotePort property. A value of zero specifies that the default port number should be used. For standard connections, the default port number is 25. An alternative port is 587, which is commonly used by authenticated clients to submit messages for delivery. For implicit SSL connections, the default port number is 465.
UserName
An optional string argument which specifies the user name to be used with authentication. If this argument is not specified, it defaults to the value of the UserName property. Note that for authentication to be performed, the Extended property must be set to True.
Password
An optional string argument which specifies the password to be used with authentication. If this argument is not specified, it defaults to the value of the Password property. Note that for authentication to be performed, the Extended property must be set to True.
Timeout
The number of seconds that the client will wait for a response before failing the operation. If this argument is not specified, the value of the Timeout property will be used as the default.
Options
A numeric value which specifies one or more options. If this argument is omitted or a value of zero is specified, a default connection will be established. This argument is constructed by using a bitwise operator with any of the following values:
Value Constant Description
0 smtpOptionNone No additional options are specified when establishing a connection with the server. A standard, non-secure connection will be used and the client will not attempt to use extended (ESMTP) features of the protocol. Note that if the mail server requires authentication, the smtpOptionExtended option must be specified.
1 smtpOptionExtended 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. This option is automatically enabled if the connection is established on port 587 because submitting messages for delivery using this port typically requires client authentication.
&H400 smtpOptionTunnel 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.
&H800 smtpOptionTrustedSite 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 either the SSL or TLS protocols.
&H1000 smtpOptionSecureExplicit This option specifies that a secure connection should be established with the server and requires that the server support either the SSL or TLS protocol. This option initiates the secure session using the STLS command.
&H2000 smtpOptionSecureImplicit This option specifies the client should attempt to establish a secure connection with the server. It should only be used when the server expects an implicit SSL connection or does not implement RFC 2595 where the STLS command is used to negotiate a secure connection with the server.
&H8000 smtpOptionSecureFallback 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.
&H40000 smtpOptionPreferIPv6 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.

Return Value

A value of zero is returned if the connection was successful. Otherwise, a non-zero error code is returned which indicates the cause of the failure.

Remarks

The Connect method establishes a connection with the mail server. All arguments are optional. If a given argument is omitted, then the corresponding property values are used as defaults. Specifying a username and password only sets the default UserName and Password property values. If authentication is required, the client must explicitly call the Authenticate method after the connection has been established.

See Also

Extended Property, HostAddress Property, HostName Property, Options Property, RemotePort Property, Authenticate Method, Disconnect Method, OnConnect Event