Friday, April 29, 2011

How do I test my email settings without sending a message?

As part of my app's config process, I have a sanity checker that validates all user-supplied data. This includes email server settings that the app uses to send email.

I'd like a simple sanity check on those settings without actually sending any email. It'd be great if this could support all standard flavors of SMTP setups including those with authentication/ssl/etc.

It doesn't need to be exhaustive but the more coverage, the better.

Currently all I do is verify I can open a connection to the given server on the given port. Something a little deeper would be nice.

Note: I'm not trying to validate email addresses--that's not relevant to this question.

From stackoverflow
  • I'm sure someone brighter and more qualified will pipe up with a better answer. However, at first blush I'd say that you cannot verify the ability to successfully send email without actually sending an email.

    However, if you want to automate the process, you can have a 'MyApp_SanityCheck@gmail.com' (or your local domain) address.

    Then you can create a watchdog application that monitors that email address, or just a simple app which programmatically interfaces with that email address and checks if an email was received within X minutes. This way you can be 100% certain that the emails are able to be sent out. This link shows how to programmatically check gmail addresses.

    An important note: If you application is sending out external emails, then it would be best if the email address you use is external, because it is possible that your server could be unable to send external emails, but internal emails go through just fine, and in that case your sanity check would send up a false positive.

    Michael Haren : @devinb: thanks for the tips. This is for internal use only, and for a quick sanity check, won't actually send anything. There's a step for that later on in the process. Thanks!
  • You just open a raw connection to the server & port that the user supplies and do a

    HELO Server.Domain.Com
    Mail From: validaccount@domain.com
    

    to see if you get a valid HELO response & Sender OK Response (if smtp authentication is enabled).

    Same as you would do if you telnet direct to the server.

    http://www.petri.co.il/test_smtp_service.htm

    This might also be useful

    http://qmail.jms1.net/test-auth.shtml

    Michael Haren : If i'm using a secure smtp server, how far will I get here? Where would I supply a password or start an SSL/TLS connection?
    Eoin Campbell : not sure t.b.h. Have never needed to test that. you could try this link. it gives some details on openssl/encoding/and using the Auth command http://qmail.jms1.net/test-auth.shtml
    Michael Haren : thanks Eoin, that extra link is very useful
    Eoin Campbell : NP. Glad to help

0 comments:

Post a Comment