Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get domain from email

How do I get the domain from an email-adress in ruby?

like image 588
jonepatr Avatar asked Jan 15 '11 13:01

jonepatr


People also ask

How do I find the domain of my email?

Use the ICANN Lookup tool to find your domain host. Go to lookup.icann.org. In the search field, enter your domain name and click Lookup. In the results page, scroll down to Registrar Information.

What is the domain of an email address?

A domain name (often simply called a domain) is an easy-to-remember name that's associated with a physical IP address on the Internet. It's the unique name that appears after the @ sign in email addresses, and after www. in web addresses.

How do I extract domain from an email in Excel?

To extract domain from email address Select a blank cell to place this formula =RIGHT(A2,LEN(A2)-FIND("@",A2)), press Enter key, and drag fill handle down to the cells which need this formula.


3 Answers

>> "[email protected]".split("@").last
=> "mycorp.com"
like image 135
miku Avatar answered Oct 19 '22 11:10

miku


If you prefer using a library dedicated to understanding these things:

→ irb -rmail
ruby-1.9.2-p0 > Mail::Address.new('[email protected]').domain
 => "example.com" 
like image 51
noodl Avatar answered Oct 19 '22 09:10

noodl


    >>  email = "Sahil Grover<[email protected]>"        
    => "Sahil Grover<[email protected]>"

    >> mail = Mail::Address.new(email)         
    => #<Mail::Address:75152940 Address: |Sahil Grover <[email protected]>| >

    >> mail.instance_values        
    => {"output_type"=>:decode,
       "parsed"=>true,
     "data"=>#<struct Mail::Parsers::AddressStruct 
     raw="Sahil Grover<[email protected]>", 
     domain="stackoverflow.com", 
     comments=[], 
     local="sahil+test", 
     obs_domain_list=nil, 
     display_name="Sahil Grover", 
     group=nil, 
     error=nil>,
     "display_name"=>"Sahil Grover"}

    >> mail.domain        
    => "stackoverflow.com"
like image 4
Sahil Grover Avatar answered Oct 19 '22 10:10

Sahil Grover