OK. Here is how to do it, but this is just to get you started. Doing it this way will only work if the SMTP server accept relays! This is shown in VB but you can see the commands to send in a telnet session (just telnet to port 25 of the e-mail server)
First drop a WinSock control on the form.
Add a 2 textboxes and name them txtRecipient and txtMessage. Then add a button called cmdSend.
Add the following code under the cmdSend Click event.
That just sent the email. Remember that this only works if the SMTP server accepts relaying.Code:If Winsock1.State <> sckClosed Then Winsock1.Close End If Winsock1.Protocol = sckTCPProtocol Winsock1.RemotePort = 25 Winsock1.RemoteHost = "Your SMTP server ie: smtp. Winsock1.Connect Winsock1.SendData "HELO " + SystemName + Chr$(13) + Chr$(10) 'Replace SystemName with the systems name (can really be anything) Winsock1.SendData "MAIL FROM:" + YourEMail + Chr$(13) + Chr$(10) 'Replace YourEMail with your (sender) email address Winsock1.SendData "RCPT TO:" + txtRecipient + Chr$(13) + Chr$(10) Winsock1.SendData "DATA" + Chr$(13) + Chr$(10) Winsock1.SendData txtMessage + Chr$(13) + Chr$(10) + "." + Chr$(13) + Chr$(10) 'Tip: After you type DATA, everything that follows is the email message. The message is sent when you enter a period "." on a line by itself (ie: Hit return then . then hit return) Winsock1.SendData "QUIT" + Chr$(13) + Chr$(10)
If you want to capture the messages sent back from the server you could add a listbox, name it lstSrvMsgs and then add the following code.
I haven't really tested this code so I hope I typed it right. Anyway, it should give you a good head start.Code:Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim InData As String Winsock1.GetData InData lstSrvMsgs.AddItem Left$(InData, Len(InData) - 2) 'Strip off Chr(13)+Chr(10) at end of string End Sub
Ryan




Reply With Quote