• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

How do I detect (from C#) whether a mail server is available?

I am wondering if it's possible to check from my C# program whether a given mail server is available.

Does anyone know?

thanks,
newbieweb
0
newbieweb
Asked:
newbieweb
  • 3
  • 2
1 Solution
 
slado2Commented:
I don't know if you want to check outgoing or incoming server but basically all you need to do is to open socket to the correct port:
SMTP: 25
POP3: 110
IMAP: 143

Look at this msdn article - all you need to do is to try to connect to the server and if that fails then you know the server is not accessible.

http://msdn2.microsoft.com/en-us/library/system.net.sockets.socket.aspx
0
 
newbiewebSr. Software EngineerAuthor Commented:
thanks.

Now is there a chance it will fail to connect because the mail server is busy, if I have a mailing going on, for example?

Or does it at least know the server is operational but slow to respond?
0
 
slado2Commented:
You can only check whether the server is listening on some port. There's no additional information such as server load, etc. If you want to check whether the server is really working you must try to perform some operation on the server (e.g. SmtpClient.Send) and check the result code.
0
 
newbiewebSr. Software EngineerAuthor Commented:
So are you saying, using the "listening on a port" method, that if it's got a heavy load it might appear to be down?
0
 
slado2Commented:
It depends on mail server. Some will deny incoming connections at all some will accept connections. Generally if you can connect to the mail server's port you must issue proper commands and it mail server's job to execute them. If the server is not able to execute command it must report an error code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now