http://www.perlmonks.org?node_id=125298

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I recently developed a script for someone that I host on my server, they run a site which allows users to enter their email address to signup for a contest, At the moment I only have a very simple regex to validate the syntax of the email - this contest site gets about 1,000 signups a day, of which of the emails the server sends out, I'm getting about 50 bounce and just sit on the server waiting for a retry, mainly this appears to be due to users spelling their email address wrong..

Then I stumbled upon Email::Valid yesterday which appears to also do an mx check on a domain, my concern with so many emails to check that this will cause a very high load on the server..
Anyone have any opinions?

Replies are listed 'Best First'.
Re: Email Validation
by rob_au (Abbot) on Nov 14, 2001 at 16:48 UTC
    While it is unlikely that MX domain checks alone will cause high server load (depending on the network and DNS configuration), you can disable this functionality within Email::Valid by setting the parameter -mxcheck to 0 - This allows you to merely check the email as valid with regard to RFC822 specification or alike. eg.

    print (Email::Valid->address( -address => 'email@address.com', -mxcheck => 0 ) ? 'yes' : 'no');

    With regard to the number of email addresses getting bounced and ending up in retry or bad message queues, it may be worth either modifying your MTA configuration to minimise retries before delivery failure or rewriting the mail code to attempt SMTP delivery to the lowest preference mail exchanger directly and discarding the message if delivery is not achieved within a set number of attempts. You could also set up a mailbox directed to /dev/null for bounce messages.

    There is of course a balance which you will be able to find between server load elevated by Email::Valid MX domain lookups and repeated MTA delivery attempts. My guess is that the load increase attributable to MX domain lookups will be negligible.

    Good luck.

     

    Ooohhh, Rob no beer function well without!

Re: Email Validation
by McD (Chaplain) on Nov 14, 2001 at 22:15 UTC
    Email::Valid is probably your best bet - any of the less rigourous methods proposed are simply biding time until they fail to validate an otherwise perfectly functional address.

    Email addresses are suprisingly complicated beasties - Mastering Regular Expressions has a regex to match valid addresses which will curl your hair - you can find it here.

    But in any case, you need to deal with failure notices - any mail, even mail to valid addresses, can fail to deliver for a variety of reasons.

    Peace,
    -McD

A reply falls below the community's threshold of quality. You may see it by logging in.