1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| Private WithEvents evt As Winsock
Private nextSend As Boolean
Private Sub btnSend_Click()
On Error GoTo trerr
Dim tmp As String
Set evt = Ws
Ws.Connect txtServer, 25
While Ws.State <> sckConnected
DoEvents
Wend
nextSend = False
Ws.SendData "HELO toto" & vbCrLf
While nextSend = False
DoEvents
Wend
nextSend = False
Ws.SendData "MAIL FROM:" & txtFrom.Text & vbCrLf
While nextSend = False
DoEvents
Wend
nextSend = False
Ws.SendData "RCPT TO:" & txtTo.Text & vbCrLf
While nextSend = False
DoEvents
Wend
nextSend = False
Ws.SendData "DATA" & vbCrLf
While nextSend = False
DoEvents
Wend
Ws.SendData "To:" & txtTo.Text & vbCrLf
Ws.SendData "From:" & txtFrom.Text & vbCrLf
Ws.SendData "Subject:" & txtSubject.Text & vbCrLf
Ws.SendData rtxtMail.Text & vbCrLf
nextSend = False
Ws.SendData vbCrLf & "." & vbCrLf
While nextSend = False
DoEvents
Wend
nextSend = False
Ws.SendData "QUIT" & vbCrLf
While nextSend = False
DoEvents
Wend
Ws.Close
Exit Sub
trerr:
Ws.Close
MsgBox Err.Description, vbCritical, "Erreur"
End Sub
Private Sub evt_Close()
rtxtLog.Text = rtxtLog.Text & vbCrLf & "Deconnexion réalisée"
End Sub
Private Sub evt_Connect()
rtxtLog.Text = rtxtLog.Text & vbCrLf & "Connexion au serveur réalisée"
End Sub
Private Sub evt_ConnectionRequest(ByVal requestID As Long)
rtxtLog.Text = rtxtLog.Text & vbCrLf & "Demande de connexion au serveur"
End Sub
Private Sub evt_DataArrival(ByVal bytesTotal As Long)
Dim tmp As String
If Ws.State = sckClosed Or Ws.State = sckClosing Then Exit Sub
Ws.GetData tmp, vbString, bytesTotal
rtxtLog.Text = txtLog.Text & Chr(13) & tmp
rtxtLog.Refresh
nextSend = True
End Sub
Private Sub evt_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
MsgBox Number & " : " & Description
End Sub |
Partager