• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • 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
 
newbiewebAuthor 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
 
newbiewebAuthor 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

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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