Abort Method


Aborts currently performed long-run operation and immediately disconnects from the SMTP server. If no long-run operation is currently performed, the method does nothing.

Long-run operation is any action which causes data exchange with the SMTP server. Connecting to the server, sending a message, graceful disconnecting, etc. are all long-run operations.

To determine whether long-run operation is currently performing, examine Busy property value.

When long-run operation is aborted, rough disconnection procedure takes place (not graceful one) so "QUIT" SMTP command is not executed. This means that some servers may discard messages prepared for relay during the current SMTP session. However, most servers relay messages regardless whether the client has sent "QUIT" command.

Once the connection is aborted, ErrCode property of SMTP object is set to value of 7 (Connection aborted by client side).

Note: Abort method can be called only if SMTP.EnableEvents=True (Async mode is on). Calling Abort method does not immediately closes the connection, it just notifies SMTP object to close it. Closing itself occures after millisecond or so after calling Abort method. This is specifics of Async mode operation.


blnResult = ObjectName.Abort  
Parameters: None 
Return value As Boolean True if successful, False if error has occurred (nothing to abort because there is no long-run operation in progress)  

Usage example:

Option Explicit
Dim WithEvents objSMTP As Object

Private Sub Command1_Click()
  Set objSMTP = CreateObject("MailBee.SMTP")
  objSMTP.LicenseKey = "put your license key here"
  objSMTP.EnableEvents = True ' Enable asynchronous mode
  objSMTP.ServerName = "mailserver.com"
  If objSMTP.Connect Then ' Long-run operation
    objSMTP.RelayMessage "C:\Data\email.eml", "from@addr.com", "to@addr.com" ' Long-run operation
    objSMTP.Disconnect ' Long-run operation
  End If
End Sub

Private Sub Form_Load()
  Set objSMTP = Nothing
End Sub

Private Sub Form_Unload(Cancel As Integer)
  If objSMTP Is Nothing Then Exit Sub
  If objSMTP.Busy Then objSMTP.Abort ' Cancel SMTP session on exit
End Sub

See Also:

Busy Property
EnableEvents Property
ErrCode Property


Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.