The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mail::CheckUser - checking email addresses for validness

SYNOPSIS

        use Mail::CheckUser qw(check_email);
        my $res = check_email($email_addr);

        use Mail::CheckUser;
        my $res = Mail::CheckUser::check_email($email_addr);

DESCRIPTION

This Perl module provides routines for checking validness of email address.

It makes several checks:

  1. it checks syntax of email address;

  2. it checks if there any MX record for specified in email domain or if there exist such host;

  3. it tries to connect to email server directly via SMTP to check if mailbox is valid. Old versions of this module have performed this check via VRFY command. Now module uses another check: it uses combination of commands MAIL and RCPT which simulates fake sending of email. Old VRFY check is still supported (see $Mail::CheckUser::Use_RCPT_Check global variable description in "GLOBAL VARIABLES"). However please note VRFY can't detect bad mailboxes in many cases while MAIL/RCPT works. For example hotmail.com can be verified with MAIL/RCPT check while VRFY check doesn't work.

If is possible to turn of all networking checks (second and third checks). See "GLOBAL VARIABLES".

This module was designed with CGIs (or any other dynamic Web content programmed with Perl) in mind. Usually it is required to check fast e-mail address in form. If check can't be finished in reasonable time e-mail address should be treated as valid. This is default policy. By default if timeout happens result of check is treated as positive (it can be overridden - see "GLOBAL VARIABLES").

EXAMPLE

This simple script checks if email address blabla@foo.bar is valid.

        use Mail::CheckUser qw(check_email);

        my $email = "blabla@foo.bar";

        if(check_email($email)) {
                print "E-mail address <$email> is OK\n";
        } else {
                print "E-mail address <$email> isn't valid\n";
        }

GLOBAL VARIABLES

It is possible to configure check_email() using global variables listed below.

  • $Mail::CheckUser::Skip_Network_Checks - if it is true then do only syntax checks. By default it is false.

  • $Mail::CheckUser::Skip_SMTP_Checks - if it is true then do not try to connect to mail server to check if user exist on it. By default it is false.

  • $Mail::CheckUser::Use_RCPT_Check - if it is true then use MAIL/RCPT check instead VRFY check. By default it is true.

  • $Mail::CheckUser::Sender_Addr - MAIL/RCPT check needs some mailbox name to perform its check. Default value is "check\@user.com"

  • $Mail::CheckUser::Timeout - timeout in seconds for network checks. By default it is 60.

  • $Mail::CheckUser::Treat_Timeout_As_Fail - if it is true Mail::CheckUser treats timeouted checks as failed checks. By default it is false.

  • $Mail::CheckUser::Debug - if it is true then enable debug output on STDERR. By default it is false.

AUTHOR

Ilya Martynov m_ilya@agava.com

SEE ALSO

perl(1).