Attribute VB_Name = "modSMTP"
'SMTP (Email) Variables
Type SMTPData
    Socket As Long
    Sending As Boolean
    Mode As Byte
    OutgoingMail As New Collection
    TimeoutTimer As Long
End Type
Public SMTP As SMTPData

Sub DeliverNow()
    Dim St As String
    With SMTP
        If .OutgoingMail.Count > 0 Then
            If .Sending = False Then
                .Socket = ConnectSock("199.170.68.11", 25, St, gHW, 1029, True)
                If Not .Socket = INVALID_SOCKET Then
                    .Sending = True
                    .Mode = 0
                    .TimeoutTimer = Timer
                Else
                    .Sending = False
                End If
            End If
        End If
    End With
End Sub

Sub CloseSMTP()
    With SMTP
        If Not .Socket = INVALID_SOCKET Then
            closesocket .Socket
            .Socket = INVALID_SOCKET
        End If
        .Sending = False
    End With
End Sub

Sub ReadSMTPData()
    Dim St As String, A As Long
    With SMTP
        St = Receive(.Socket)
        If Len(St) > 0 Then
            A = InStr(St, " ")
            If A > 1 Then
                St = Left$(St, A - 1)
            End If
            Select Case Val(St)
                Case 250
                    Select Case .Mode
                        Case 1
                            SendSMTP "RCPT TO:" + .OutgoingMail(1).Receiver + Chr$(13) + Chr$(10)
                            .Mode = 2
                        Case 2
                            SendSMTP "DATA" + Chr$(13) + Chr$(10)
                        Case 3
                            .OutgoingMail.Remove (1)
                            If .OutgoingMail.Count > 0 Then
                                .Mode = 1
                                SendSMTP "MAIL FROM:lew@shaysnet.com" + Chr$(13) + Chr$(10)
                            Else
                                .Mode = 0
                                CloseSMTP
                            End If
                    End Select
                Case 354
                    If .Mode = 2 Then
                        SendSMTP SMTP.OutgoingMail(1).Data + Chr$(13) + Chr$(10) + "." + Chr$(13) + Chr$(10)
                        .Mode = 3
                    End If
            End Select
        End If
    End With
End Sub
Sub SendMail(Receiver As String, Data As String)
    Dim Mail As New clsMail
    Mail.Receiver = Receiver
    Mail.Data = Data
    SMTP.OutgoingMail.Add Mail
    DeliverNow
End Sub

Sub SendSMTP(ByVal St As String)
    SendData SMTP.Socket, St
End Sub
