Skip to main content
Inspiring
June 15, 2011
Question

How to verify mail server is up or not

  • June 15, 2011
  • 1 reply
  • 306 views

Hi there,

I have web page with a form. When a user hits the submit button the form content stored in variable emailbody is emailed. I was wondering if there is any way to catch the exception when the mail server is down or not reachable. I did the following but ColdFusion is not throwing any exceptions even though I know for sure the mail server is down.

Any clues?

Thanks

Joe

<cftry>

<cfmail

  from="me@something.com"

  to="you@something.com"

  subject="Test Email"

  type="html"

  server="mail.test.com">

        #emailbody#

</cfmail>

<cfcatch type="any">

            <cfoutput>Due to #cfcatch.Detail# we are unable to email your comment.</cfoutput>

</cfcatch>

</cftry>

    This topic has been closed for replies.

    1 reply

    Owainnorth
    Inspiring
    June 15, 2011

    Not that easily you can't, as that's not entirely how CFMAIL works.

    All a CFMAIL does is creates a text file in your ColdFusion\mail\spool folder, a separate thread comes along at a set interval and tries to send it, by which point your user is off doing something else.

    The only think you could perhaps do is use Java to test a connection to localhost on port 25, but you're then lumbering your users with the error message if SMTP isn't running, even though it would probably send their email when it came back up anyway.

    Personally I'd look into having a separate monitoring process on the \spool and \undeliver folders to look for messages (or messages that have been there too long) which would alert you to problems. No point giving your users unnecessary error messages.