Raku Land

Email::Valid

github:Demayl

Email::Valid

Email::Valid - raku programming language library to validate/parse email addresses

Synopsis

use v6.c;
use Email::Valid;

my $email = Email::Valid.new(:simple); # By default :simple( True )

if $email.validate("test@domain.tld") {
    say "test@domain.tld is valid";
}

say "Mailbox is: " ~ $email.parse('test@domain.tld')<email><mailbox>;
say "Domain is: "  ~ $email.parse('test@domain.tld')<email><domain>;
# Mailbox is: test
# Domain is: domain.tld

# Variant with custom type
my Email $str = 'test@test.com';

Description

This module validates if given email is valid. It's a validation only for "most" popular email types. It allows IDN domains ( 'xn--' ) and IP address domains ( IPv4 + IPv6 ) disabled by default

Methods

Constructor

Examples

Enable MX check

my $email = Email::Valid.new(:simple(False), :mx_check, :ns_server('8.8.8.8'), :ns_server_timeout(5) );

if !$email.validate("test@domain.tld") {
    say "test@domain.tld is NOT valid";
}

Extract emails from text & validate them

my $txt   = 'Some mails - <mail1@dont-exist.com,mail2@mail.com>'
my $email = Email::Valid.new(:!simple, :mx_check );

$email.extract( $txt, :validate ) ; 
# (mail2@mail.com) because it has valid MX record

TODO