CheckUser(3pm) | User Contributed Perl Documentation | CheckUser(3pm) |
Mail::CheckUser - check email addresses for validity
use Mail::CheckUser qw(check_email); my $ok = check_email($email_addr); use Mail::CheckUser qw(:constants check_email last_check) my $ok = check_email($email_addr); print "DNS timeout\n" if last_check()->{code} == CU_DNS_TIMEOUT; use Mail::CheckUser; my $res = Mail::CheckUser::check_email($email_addr);
This Perl module provides routines for checking validity of email address.
It makes several checks:
If is possible to turn off some or all networking checks (items 2 and 3). 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 quickly check e-mail addresses in forms. If the check can't be finished in reasonable time, the e-mail address should be treated as valid. This is the default policy. By default if a timeout happens the result of the check is treated as positive. This behavior can be overridden - see "GLOBAL VARIABLES".
In many cases there is no way to detect the validity of email addresses with network checks. For example, non-monolithic mail servers (such as Postfix and qmail) often report that a user exists even if it is not so. This is because in cases where the work of the server is split among many components, the SMTP server may not know how to check for the existence of a particular user. Systems like these will reject mail to unknown users, but they do so after the SMTP conversation. In cases like these, the only absolutely sure way to determine whether or not a user exists is to actually send a mail and wait to see if a bounce messages comes back. Obviously, this is not a workable strategy for this module. Does it mean that the network checks in this module are useless? No. For one thing, just the DNS checks go a long way towards weeding out mistyped domain parts. Also, there are still many SMTP servers that will reject a bad address during the SMTP conversation. Because of this, it's still a useful part of checking for a valid email address. And this module was designed such that if there is exists possibility (however small) that the email address is valid, it will be treated as valid by this module.
Another warning is about $Mail::CheckUser::Treat_Timeout_As_Fail global variable. Use it carefully - if it is set to true then some valid email addresses can be treated as bad simply because an SMTP or DNS server responds slowly.
Another warning is about $Mail::CheckUser::Treat_Full_As_Fail global variable. Use it carefully - if it is set to true then some valid email addresses can be treated as bad simply because their mailbox happens to be temporarily full.
This simple script checks if email address "blabla@foo.bar" is valid.
use Mail::CheckUser qw(check_email last_check); 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: ", last_check()->{reason}, "\n"; }
{ ok => OK, code => CODE, reason => REASON }
Constants used by "last_check" to describe result of last check can be exported with
use Mail::CheckUser qw(:constants)
List of all defined constants:
It is possible to configure "check_email" using the global variables listed below.
Ilya Martynov ilya@martynov.org
Rob Brown bbb@cpan.org
Module maintained at Source Forge ( http://sourceforge.net/projects/mail-checkuser/ ).
Copyright (c) 1999-2003 by Ilya Martynov. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
$Id: CheckUser.pm,v 1.46 2003/09/18 23:51:36 hookbot Exp $
2022-06-15 | perl v5.34.0 |