Email::Handle - A Objective Email Handler


  use Email::Handle;

  my $email = Email::Handle->new('');
  print $email->is_valid ? 'yes' : 'no';
  print $email->obfuscate;
  print $email->anonymize;
  print $email;
  $email->send(From => '');

This module is also convenient for using on the DB application with Template and Class::DBI / DBIx::Class.

  # setup the table that has column of email with this module
  my $loader = Class::DBI::Loader->new(
     namespace => 'MyApp'
  $loader->find_class('user')->has_a(email => 'Email::Handle');

  # then output records with TT2
  my $tmpl = Template->new;
      { users => $loader->find_class('user')->retrieve_all }

  # You can write the template with some methods of this module like this
  [% WHILE (user IN users) %]
  [% IF %]
  [% END %]


This module allows you to handle an email address as a object.



Returns Email::Handle object. It has three forms of construction.

  my $email = Email::Handle->new('');


  my $email = Email::Handle->new(
     user => 'root',
     host => ''


  my $email = Email::Handle->new;


Set/get an email address. A passed string will be splited and setted as user and host internally.


Returns a Email::Handle object to a plain string. Email::Handle objects are also converted to plain strings automatically by overloading. This means that objects can be used as plain strings in most Perl constructs.

  my $email = Email::Handle->new('');
  print $email->as_string; # ''
  print $email;            # ''


Set/get a user name for an email address.

  $email->user;        # 'root'
  $email->user('foo'); # changing the user from 'root' to 'foo'


Set/get a host name for an email address.

  $email->host;             # ''
  $email->host(''); # changing the host from '' to ''


Validates whether an address is well-formed with Email::Valid/Email::Valid::Loose and returns false if the address is not valid. This method takes some options as arguments.

  $email->is_valid;             # validating with Email::Valid
  $email->is_valid(loose => 1); # validating with Email::Valid::Loose

  # Any other arguments will be passed to the validator.
  $email->is_valid(-mxcheck => 1);


Returns obfuscated HTML email addresses which is hard to be scraped. It requires "HTML::Email::Obfuscate ".


This code generates obfuscated strings like this:

  ro&#x6F;<span>t</span><!-- @ -->&#64;h&#x61;t<span>e</span>na<B>&#46;</b>n&#x65;<B>&#46;</b><span>j</span>&#x70;

Arguments will be passed to the constructor of the HTML::Email::Obfuscate.

  $email->obfuscate(javascript => 1);
  $email->obfuscate(lite => 1);


Returns an anonymized email address like this:

  $email->anonymize;        # 'root@e...'
  $email->anonymize('***'); # 'root@e***'


Returns MIME::Lite message object for sending mail to the address. Arguments will be passed to the constructor of MIME::Lite;

      From => '', 
      Subject => 'Hello'

If you want to use any other MIME classes like MIME::Lite::TT rather than MIME::Lite, override package variable $Email::Handle::MIME_CLASS

  $Email::Handle::MIME_CLASS = 'MIME::Lite::TT';
  my $msg = $email->mime(...)


A shortcut method for sending mail with MIME::Lite.

  $email->send(From => '', Subject => 'Hello');


Naoya Ito, <naoya at>


Please report any bugs or feature requests to bug-email-handle at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Email::Handle

You can also look for information at:


Copyright 2006 Naoya Ito, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 203:

L<> starts or ends with whitespace