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

Posted on 2007-10-14
Last Modified: 2013-12-17
I am wondering if it's possible to check from my C# program whether a given mail server is available.

Does anyone know?

Question by:newbieweb
    LVL 8

    Expert Comment

    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.

    Author Comment


    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?
    LVL 8

    Accepted Solution

    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.

    Author Comment

    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?
    LVL 8

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now