event StateChange (Msg as Message, NewState as SendStateEnum)

Occurs during sending the message, while the sending's state is changing/changed.

TypeDescription
Msg as Message A Message object that contains the email message being sent to the SMTP server.
NewState as SendStateEnum A SendStateEnum expression that indicates the state of the sending operation.

The StateChange event is fired each time when the sending state is changing/changed. Use the Debug event to debug sending a message.   Here are the steps that the ExEMail component follows in order to deliver an email message:

  1. The control fires BeginSend() event
  2. The control takes the domain recipent's email address. The control fires StateChange(...,LookupMX)
  3. The control sends a query to the DNS server in order to get the SMTP hosts that are responsible for the domain.
  4. Based on the DNS's response, the control is trying each SMTP server found to deliver the email message. The control fires Debug event, in order to let the application knows what's the host where the control is trying to deliver the email message. The control fires StateChange(...,Connecting)
  5. Once that the control is connected to the SMTP server, the StateChange(...,Connected) is fired.
  6. When the control says hello to the server.  it fires StateChange(...,Opening)
  7. The control fires StateChange(...,Opened), after server replies to the hello command.
  8. The control prepares and sends the information about the sender and recipents email addresses.
  9. If the server accepts the sender and the recipents, the control prepares the message's DATA to send it to the SMTP server. Before starting any data to the server, the control fires StateChange(...,Data). During sending message's data the control fires Data event.
  10. Once that message's data was delivered, the control is going to close the connection. It fires StateChange(...,Disconnecting)
  11. The client is going to inform the server that wants to close the connection. The control fires StateChange(...,Closing)
  12. The client sends QUIT command to the server, and fires the StateChange(...,Closed)
  13. The client is disconnected, and the control fires StateChange(...,Disconnected)
  14. The control fires EndSend() event

The events are fired only if the Notifier property points to an EMail object. For instance the following sample displays the message's state during sending:

Dim WithEvents e As EMail

Private Sub e_StateChange(ByVal Msg As EXEMAILLibCtl.IMessage, ByVal NewState As EXEMAILLibCtl.SendStateEnum)
    Select Case NewState
        Case SendStateEnum.LookupMX
            Debug.Print "LookupMX"
        Case SendStateEnum.Connected
            Debug.Print "Connected"
        Case SendStateEnum.Connecting
            Debug.Print "Connecting"
        Case SendStateEnum.Opening
            Debug.Print "Opening"
        Case SendStateEnum.Opened
            Debug.Print "Opened"
        Case SendStateEnum.Data
            Debug.Print "Data"
        Case SendStateEnum.Closing
            Debug.Print "Closing"
        Case SendStateEnum.Closed
            Debug.Print "Closed"
        Case SendStateEnum.Disconnecting
            Debug.Print "Disconnecting"
        Case SendStateEnum.Disconnected
            Debug.Print "Disconnected"
    End Select
End Sub

Private Sub Form_Load()

    ' Creates an EMail object, that will receive Message notifications
    Set e = Runtime1.NewEMail()
    ' Creates a Message object
    Dim m As Message
    Set m = Runtime1.NewMessage()
    ' Message' notifications are sent through EMail object
    Set m.Notifier = e

    ' Sends a message to one user
    m.Send "m@malibu.com", "marfa@cool.com", "Test", "The message has one attchament", "c:\winnt\system32\setup.exe"
End Sub