Establish a connection with the specified mail server.
Syntax
object.Connect( [Server] [, Port] [,
Username] [, Password] [, Timeout] [,
Options] )
The Connect method syntax has the following parts:
| Part |
Description |
| object
|
An object expression that
evaluates to an InternetMail object. |
| server
|
A string which specifies the host
name or IP address of the mail server. |
| port
|
A long integer which specifies the
mail server port number. |
| username
|
A string which specifies the
username. |
| password
|
A string which specifies the
password. |
| timeout
|
A long integer which specifies the
timeout period in seconds. |
| options
|
A long integer which specifies one
or more options. |
Return Type
Integer
Settings
The settings for Options are:
| Value |
Constant |
Description |
| 1 |
mailOptionImplicitSSL |
This option specifies that an
implicit SSL session should be established with the mail server and
prevents the use of a command which is used to negotiate an
explicit SSL connection. This option should only be used if it is
required. |
| 2 |
mailOptionAPOP |
Causes the APOP authentication
method to be used when connecting to a POP3 mail server. The
default is to use standard password authentication. |
Remarks
The Connect method is used to establish a connection with
the specified mail server. This is the first method that must be
called prior to the application retrieving mail messages using the
GetMessage method.
If the Connect method is called when a connection already
exists, the current connection will be closed. This has the
side-effect of causing any messages which have been marked for
deletion to be removed by the mail server.
Note that it is not required to call the Connect method
to send messages since this is handled internally by the component.
For more information about sending messages, see the
SendMessage method and the RelayServer and
RelayPort properties.
This method will return a value of zero if the action was
successful. Otherwise, a non-zero error code is returned which
indicates the cause of the failure.
Example
The following example connects to a mail server and retrieves
each of the mail messages, storing them in a file on the local
system:
Dim strFileName As String
Dim nMessage As Long, nError As Long
nError = InternetMail1.Connect(strServerName, , strUserName, strPassword)
If nError <> 0 Then
MsgBox "Unable to connect to " & strServerName & vbCrLf & _
InternetMail1.LastErrorString, vbExclamation
Exit Sub
End If
If InternetMail1.LastMessage = 0 Then
MsgBox "The mailbox is currently empty", vbInformation
InternetMail1.Disconnect
Exit Sub
End If
For nMessage = 1 To InternetMail1.LastMessage
strFileName = "c:\temp\msg" & Format(nMessage, "00000") & ".txt"
nError = InternetMail1.StoreMessage(nMessage, strFileName)
If nError <> 0 Then
MsgBox "Unable to store message " & nMessage & vbCrLf & _
InternetMail1.LastErrorString, vbExclamation
Exit For
End If
Next
If nError = 0 Then
MsgBox "Stored " & InternetMail1.LastMessage & " messages", vbInformation
End If
InternetMail1.Disconnect
See Also
RelayPort Property,
RelayServer Property,
Secure Property, ServerName Property, ServerPort Property, ServerType Property, Disconnect Method, GetMessage Method, SendMessage Method
|