Sending Email w/Winsock  
Ok, well let's see... I'll try and describe how the code below works and hopefully you can go from there. First off, in the declarations you will notice an Enum statement:

Private Enum SMTP_State
     MAIL_CONNECT
     MAIL_HELO
     MAIL_FROM
     MAIL_RCPTTO
     MAIL_DATA
     MAIL_DOT
     MAIL_QUIT
End Enum

Now if your not familiar with enum statements yet, it basically lets you create a new type, which is an integer type variable that lets you specify names for each value. For instance in this one, MAIL_CONNECT would be 0, MAIL_HELO would be 1 and so on. So when SMTP_State = 1 it also = MAIL_HELO. 

Next in the declarations you see:

Private m_State As SMTP_State

Which is just declaring m_State as that new enum we created.

And then of course we Dim all the string variables to hold all our addresses and message subject and message body etc.

The way the whole thing works is when the SendEmail Sub is run, it collects all the message info and then tells winsock to connect to your mail server. ( you have to specify that and save it to the EMLHost variable. ) and connects to it in port 25.

The rest is done in the DataArrival Event. When its connected the server will send you a string that starts with a number. If the number is 250, 220,or 354 then basically that's your green light, your go ahead to send the next part.

The steps are as follows:

Once connected, send the HELO string with your mailbox. If your 'From' Address was general@xi0n.com then the mailbox would be general

Winsock1.SendData "HELO general"  & vbCrLf

Then once that's accepted send the MAIL FROM string:

Winsock1.SendData "MAIL FROM:general@xi0n" & vbCrLf

...once accepted send the RCPT (recipient) TO string:

Winsock1.SendData "RCPT TO:support@xi0n.com" & vbCrLf

...once accepted we tell the server its data now:

Winsock1.SendData "DATA" & vbCrLf

...and once that's accepted you'll see its just a matter of sending the subject, and then the message line for line. Once that's complete then you send a dot to let the server know its done with the data part.

Winsock1.SendData "." & vbCrLf

Then just send the QUIT string:

Winsock1.SendData "QUIT" & vbCrLf

And close your winsock.

 

     Declarations  
 

'//--------------------------------------------------------------------------------

Private Enum SMTP_State
     MAIL_CONNECT
     MAIL_HELO
     MAIL_FROM
     MAIL_RCPTTO
     MAIL_DATA
     MAIL_DOT
     MAIL_QUIT
End Enum

Private m_State As SMTP_State

Dim EMLFrom As String
Dim EMLTo As String
Dim EMLHost As String
Dim EMLSubject As String 
Dim EMLMsg As String

'//--------------------------------------------------------------------------------

     Code  
  

'//--------------------------------------------------------------------------------
'// Command Button To Send
'//--------------------------------------------------------------------------------

Private Sub SendEmail()

 'save the 'From' address 
 EMLFrom = "MyEmailAddy"

 'save the 'To' address
 EMLTo = "DestEmailAddy"

 'save the STMP Host address
 EMLHost = "MyMailSvr.com"

 'save the Subject
 EMLSubject = "The Email Subject"

 'and then save the message body
 EMLMsg = "What I Want To Send..."

'now connect to the STMP host on port 25
 Winsock1.Connect Trim$(EMLHost), 25

 m_State = MAIL_CONNECT

End Sub

'//--------------------------------------------------------------------------------

'//--------------------------------------------------------------------------------
'// DataArrival Event for Winsock
'//--------------------------------------------------------------------------------

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim strServerResponse As String
Dim strResponseCode As String
Dim strDataToSend As String

'Retrive data from winsock buffer
Winsock1.GetData strServerResponse

'Get server response code (first three symbols)
strResponseCode = Left(strServerResponse, 3)

'Only these three codes tell us that previous
'command accepted successfully and we can go on
If strResponseCode = "250" Or _
strResponseCode = "220" Or _
strResponseCode = "354" Then

Select Case m_State
Case MAIL_CONNECT
    
   
'Change current state of the session
    m_State = MAIL_HELO

   
'Remove blank spaces
    strDataToSend = Trim$(EMLFrom)

   
'Retrieve mailbox name from e-mail address
    strDataToSend = Left$(strDataToSend, _
    InStr(1, strDataToSend, "@") - 1)
    
   
'Send HELO command to the server
    Winsock1.SendData "HELO " & strDataToSend & vbCrLf


Case MAIL_HELO

   
'Change current state of the session
    m_State = MAIL_FROM

   
'Send MAIL FROM command to the server
    Winsock1.SendData "MAIL FROM:" & Trim$(EMLFrom) & vbCrLf

Case MAIL_FROM

   
'Change current state of the session
    m_State = MAIL_RCPTTO

   
'Send RCPT TO command to the server
    Winsock1.SendData "RCPT TO:" & Trim$(EMLTo) & vbCrLf

Case MAIL_RCPTTO

   
'Change current state of the session
    m_State = MAIL_DATA

   
'Send DATA command to the server
    Winsock1.SendData "DATA" & vbCrLf

Case MAIL_DATA

   
'Change current state of the session
    m_State = MAIL_DOT

   
'So now we are sending a message body
    'Each line of text must be completed with
    'linefeed symbol (Chr$(10) or vbLf) not with vbCrLf


   
'Send Subject line
    Winsock1.SendData "Subject: " &
EMLSubject & vbLf

    Dim varLines As Variant
    Dim varLine As Variant

   
'Parse message to get lines (for VB6 only)
    varLines = Split(EMLMsg, vbCrLf)

  
  'Send each line of the message
    For Each varLine In varLines
        Winsock1.SendData CStr(varLine) & vbLf
    Next

    'Send a dot symbol to inform server
    'that sending of message completed

    Winsock1.SendData "." & vbCrLf

Case MAIL_DOT
 
   'Change current state of the session
    m_State = MAIL_QUIT

 
   'Send QUIT command to the server
    Winsock1.SendData "QUIT" & vbCrLf

Case MAIL_QUIT

 
   'Close connection
    Winsock1.Close

End Select

Else

'If we are here server replied with
'unacceptable respose code therefore we need
'close connection and inform user about problem


Winsock1.Close

    If Not m_State = MAIL_QUIT Then
        MsgBox "SMTP Error: " & strServerResponse
    Else
        MsgBox "Log sent successfuly." 
    End If

End If

End Sub