Checking an SMTP connection is available on port 25

muckerz

New member
Joined
Dec 28, 2011
Messages
3
Programming Experience
1-3
Hey guys,

Long story short, I wrote a monitoring system to keep an eye on some various systems we use at work.
I need to add to it the ability to monitor two seperate mail servers, one hmail and one exchange.

I can ping them no problem to make sure the server itself is up, but i also want to check the smtp service is running.

Can anyone tell me how i can send a SMTP helo command and read in the response or suggest a different way to achieve this goal?

Thanks!
 
You can use the TcpClient class. Connect and use StreamReader to read from its NetworkStream (GetStream). It is sufficient calling ReadLine once because server should immediately upon connection reply with a 220 "Service ready" message.
 
You can use the TcpClient class. Connect and use StreamReader to read from its NetworkStream (GetStream). It is sufficient calling ReadLine once because server should immediately upon connection reply with a 220 "Service ready" message.

Thanks John - you wouldnt happen to have any examples of the TCPClient class being used in a similar way that I can look at and use to figure out what I need to do would you?

Thanks in advance! :)
 
        Using tcp As New Net.Sockets.TcpClient("domain.com", 25),
            reader As New IO.StreamReader(tcp.GetStream),
            writer As New IO.StreamWriter(tcp.GetStream) With {.AutoFlush = True}

            Dim s = reader.ReadLine 'server initial reply

            writer.WriteLine("QUIT")
            s = reader.ReadLine

        End Using

I also recommend you read the relevant .Net documentation and the SMTP protocol.
 
Yeah SMTP is one of those nasties... I just discovered recently that .NET does not support implicit SSL or TLS connections through System.Net.Mail. Apparently they do not stray from the RFC's even if everyone else does.
 
Back
Top