Domanda Come ottenere il dominio dalla posta elettronica


Come ottengo il dominio da un indirizzo email in ruby?


27
2018-01-15 13:13


origine


risposte:


>> "hey@mycorp.com".split("@").last
=> "mycorp.com"

57
2018-01-15 13:18



Se preferisci usare una libreria dedicata alla comprensione di queste cose:

→ irb -rmail
ruby-1.9.2-p0 > Mail::Address.new('feep+wibble@example.com').domain
 => "example.com" 

38
2018-01-15 13:43



    >>  email = "Sahil Grover<sahil+test@stackoverflow.com>"        
    => "Sahil Grover<sahil+test@stackoverflow.com>"

    >> mail = Mail::Address.new(email)         
    => #<Mail::Address:75152940 Address: |Sahil Grover <sahil+test@stackoverflow.com>| >

    >> mail.instance_values        
    => {"output_type"=>:decode,
       "parsed"=>true,
     "data"=>#<struct Mail::Parsers::AddressStruct 
     raw="Sahil Grover<sahil+test@stackoverflow.com>", 
     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"

1
2017-11-18 07:29