How can I test SMTP is up and running via C# without sending a message.
I could of course try:
try{
// send email to "nonsense@example.com"
}
catch
{
// log "smtp is down"
}
There must be a more tidy way to do this.
How can I test SMTP is up and running via C# without sending a message.
I could of course try:
try{
// send email to "nonsense@example.com"
}
catch
{
// log "smtp is down"
}
There must be a more tidy way to do this.
I use this method and classes to validate the credentials (link to github):
SmtpConnectorBase:
SmtpConnectorWithoutSsl:
SmtpConnectorWithSsl:
Here is a nice open source tool (does more than MX): http://www.codeproject.com/KB/IP/DNS_NET_Resolver.aspx
You could open up the port (25) with a socket or
TcpClient
and see if it responds.Open a socket connection to the smtp server on port 25 and see if you get anything. If not, no smtp server.
You can try saying
EHLO
to your server and see if it responds with250 OK
. Of course this test doesn't guarantee you that you will succeed sending the mail later, but it is a good indication.And here's a sample:
And here's the list of codes to expect.