Mojo::Email::Checker::SMTP - Email checking by smtp with Mojo enviroment. (IDN supported)
use strict; use Mojolicious::Lite; use Mojo::IOLoop::Delay; use Mojo::Email::Checker::SMTP; my $checker = Mojo::Email::Checker::SMTP->new; post '/' => sub { my $self = shift; my $request = $self->req->json; my @emails; my $delay = Mojo::IOLoop::Delay->new; $delay->on(finish => sub { $self->render(json => \@emails); }); my $cb = $delay->begin(); for (@{$request}) { my $cb = $delay->begin(0); $checker->check($_, sub { push @emails, $_[0] if ($_[0]); $cb->(); }); } $cb->(); }; app->start;
Check for email existence by emulation smtp session to mail server (mx or direct domain, cycling for multiple ip) and get response. Mechanism description http://en.wikipedia.org/wiki/Callback_verification
This is Checker object constructor. Available parameters are:
Timeout (seconds) for all I/O operations like to connect, wait for server response and NS Lookup. (15 sec. is default).
HELO value for smtp session ("ya.ru" :) is default). Use your own domain name for this value.
Enable caching for nslookup operation. In value, cache records timeout (in seconds). For example (cache => 3600) for one hour. Cache disabled if 0 value or undefined.
Main function for checking.
String with email address ("foo@foobox.foo")
Reference to callback function (see SYNOPSIS for example). Pass to CALLBACK two parameters, 1. valid (see comment) EMAIL (STR), 2. ERROR (STR) message.
Comment: If EMAIL and ERROR is defined, it's mean that reject from smtp server recieved before RCPT command. In other cases only one parameter is defined.
Copyright Anatoly Y. <snelius@cpan.org>. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Mojo::Email::Checker::SMTP::Cache, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Email::Checker::SMTP::Cache
CPAN shell
perl -MCPAN -e shell install Mojo::Email::Checker::SMTP::Cache
For more information on module installation, please visit the detailed CPAN module installation guide.