<c j anderson>; "mcp" <st*********@hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP15.phx.gbl...
http://www.faqs.org/rfcs/rfc821.html)
Using the above plus the tcpClient help in VS I contructed this. I am sure
it can be improved (quick attempt) and there is no validation on the return
strings:
Tested and works:
Imports System.Net.Sockets
Imports System.Text
Dim tcpClient As New TcpClient()
Try
tcpClient.Connect("mail.btopenworld.com", 25)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' HELO
' Does a simple write.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("HELO
<yourdomain.com>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Reads the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))
' Returns the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
MsgBox((returndata))
' MAIL FROM
sendBytes = Encoding.ASCII.GetBytes("MAIL
FROM:<fr**********@hisdomain.com>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes2(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes2, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes2)
MsgBox((returndata))
' RCPT TO
sendBytes = Encoding.ASCII.GetBytes("RCPT
TO:<to********@yourdomain.com>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes3(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes3, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes3)
MsgBox((returndata))
' DATA
sendBytes = Encoding.ASCII.GetBytes("DATA" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes4(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes4, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes4)
MsgBox((returndata))
' Finally the message
Dim txtData As String = _
"Date: 15 May 2005 11:00:00" & vbCrLf & _
"From:
fr**********@hisdomain.com" & vbCrLf & _
"To:
to********@yourdomain.com" & vbCrLf & _
"Subject: This is a test message" & vbCrLf & vbCrLf & _
"This is the body of the message" & vbCrLf & "." & vbCrLf
'Message
sendBytes = Encoding.ASCII.GetBytes(txtData)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes5(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes5, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes5)
MsgBox((returndata))
' Close connection
tcpClient.Close()
Else
If Not networkStream.CanRead Then
MsgBox("You can not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
MsgBox("You can not read data from this stream")
tcpClient.Close()
End If
End If
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try