Re: Email Socket Question



Completed simple server to receive mail. Thanks for you help.

Sub ListenToServer()
'Try

Dim LISTENING As Boolean
Dim localhostAddress As IPAddress =
ipAddress.Parse(ipAddress.ToString)
Dim port As Integer = 25 '' PORT ADDRESS
''''''''''' making socket tcpList ''''''''''''''''
Dim tcpList As New TcpListener(localhostAddress, port)
Try
tcpList.Start()
LISTENING = True

Do While LISTENING

Do While tcpList.Pending = False And LISTENING = True
' Yield the CPU for a while.
Thread.Sleep(10)
Loop
If Not LISTENING Then Exit Do

Dim tcpCli As TcpClient = tcpList.AcceptTcpClient()
Dim ns As NetworkStream = tcpCli.GetStream
Dim sr As New StreamReader(ns)

Dim returnedData As String = "220 smtp.sample.com SMTP
server ready"
Dim sw As New StreamWriter(ns)
sw.WriteLine(returnedData)
sw.Flush()
Dim receivedData As String = sr.ReadLine()
sw.Flush()


returnedData = "250 smtp.sample.com Hello
[71.105.78.90]"
sw.WriteLine(returnedData)
sw.Flush()
receivedData = sr.ReadLine()
receivedData = Trim(Replace(LCase(receivedData), "mail
from:", ""))

returnedData = "250 " + receivedData + "....Sender OK"
sw.WriteLine(returnedData)
sw.Flush()
receivedData = sr.ReadLine()


returnedData = "250 " +
Trim(Replace(LCase(receivedData), "rcpt to:", ""))
sw.WriteLine(returnedData)
sw.Flush()
receivedData = sr.ReadLine()


returnedData = "354 Start mail input; end with
<CRLF>.<CRLF>"
sw.WriteLine(returnedData)
sw.Flush()

Do While receivedData <> "."

receivedData = sr.ReadLine()
sw.Flush()
MsgBox(receivedData)

Loop
MsgBox("OVER")
returnedData = "250 Queued mail for delivery"
sw.WriteLine(returnedData)
sw.Flush()

sr.Close()
sw.Close()
ns.Close()
tcpCli.Close()
Loop
tcpList.Stop()
Catch ex As Exception
'error
LISTENING = False
End Try
End Sub
iMaiden wrote:
Thanks Branco

Dim Listener As New TcpListener("25")
Listening = True
Listener.Start()
Do Until Listening = False
Dim sb As New SocketAndBuffer()
sb.Socket = Listener.AcceptSocket()
sb.Socket.BeginReceive(sb.Buffer, 0, sb.Buffer.Length,
SocketFlags.None, AddressOf ReceiveCallBack, sb)
Loop


Branco Medeiros wrote:
googlegroups@xxxxxxxxxxxxxxxxxxx wrote:
I am learning vb.net and trying to create a simple program to watch
port 25 and receive email. I do not need any advanced features. I
just need to connect, watch and grab the emails as they come. This
seems like it should be a pretty simple but I can not seem to find any
examples in vb.net 8. Any help is appreciated. TIA

TCPListener is your friend (It's in System.Net.Sockets).

HTH.

Regards,

Branco.

.



Relevant Pages

  • Re: Receive Error: Unable to Read Data From The Transport Connection
    ... wrote a app that works like a chat app with a sender and a receiver ... connection: An existing connection was forcibly closed by the remote host. ... How can I keep the connection listener listening for new traffic? ... Dim t1 As New Thread ...
    (microsoft.public.dotnet.general)
  • Unable to Read Data From Transport Connection
    ... connection: An existing connection was forcibly closed by the remote host. ... How can I keep the connection listener listening for new traffic? ... Dim t1 As New Thread ... Dim server As TcpListener ...
    (microsoft.public.dotnet.distributed_apps)
  • Receive Error: Unable to Read Data From The Transport Connection
    ... connection: An existing connection was forcibly closed by the remote host. ... How can I keep the connection listener listening for new traffic? ... Dim t1 As New Thread ... Dim server As TcpListener ...
    (microsoft.public.dotnet.general)
  • Email Sockets Question
    ... Dim Listener As New TcpListener ... Dim sb As New SocketAndBuffer() ... Do Until Listening = False ... Private Sub ReceiveCallBack ...
    (microsoft.public.dotnet.languages.vb)
  • Understanding tcpListener
    ... tcpList.AcceptTcpClientline and doesn't hear the incoming request. ... and this seems to be listening on the local address ... Dim localhostAddress As System.Net.IPAddress = IPAddress.Loopback ... ' Wait for the next client to make a request. ...
    (microsoft.public.dotnet.languages.vb)