Re: Sockets Hanging with SMTP server code
From: Tom Shelton (tom_at_YOUKNOWTHEDRILLmtogden.com)
Date: 10/28/04
- Next message: Larry Serflaten: "Re: for each loop in a checkbox"
- Previous message: Herfried K. Wagner [MVP]: "Re: Install on many computers"
- In reply to: Dave: "Sockets Hanging with SMTP server code"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 28 Oct 2004 15:46:51 -0700
In article <3cb859f7.0410280820.6151ccf3@posting.google.com>, Dave wrote:
> Hello,
>
> I am trying to write an application that will talk to an SMTP server
> using sockets. I can connect to the server just fine, then I can
> receive the first message from the server. I can then send out a
> command to the server, but after that the thing just hangs when I am
> waiting for a response. I can't understand why this is happening. I am
> new to this language, so this might be something obvious that I am
> overlooking. Any help would be great. Here is the code. I based this
> code off an example from msdn.
<snip>
Simple code example:
Option Strict On
Option Explicit On
Imports System
Imports System.IO
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Module Module1
Sub Main()
' Declare a socket, and get our servers address
Dim connection As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
Dim serverIP As IPAddress =
Dns.GetHostByName("smtpserver.com").AddressList(0)
' Connect the socket
connection.Connect(New IPEndPoint(serverIP, 25))
' Create a reader and a writer
Dim reader As New StreamReader(New NetworkStream(connection,
False))
Dim writer As New StreamWriter(New NetworkStream(connection,
True))
writer.AutoFlush = True
writer.NewLine = vbCrLf ' so this will be protable to Unix :)
writer.WriteLine("HELO smtpserver.com")
Console.WriteLine(reader.ReadLine())
connection.Close()
End Sub
End Module
SMTP commands need to be terminated with a CrLF pair :)
HTH
-- Tom Shelton [MVP]
- Next message: Larry Serflaten: "Re: for each loop in a checkbox"
- Previous message: Herfried K. Wagner [MVP]: "Re: Install on many computers"
- In reply to: Dave: "Sockets Hanging with SMTP server code"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|