How to get domain from email

后端 未结 3 362
-上瘾入骨i
-上瘾入骨i 2021-02-02 07:15

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

相关标签:
3条回答
  • 2021-02-02 07:57

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

    → irb -rmail
    ruby-1.9.2-p0 > Mail::Address.new('feep+wibble@example.com').domain
     => "example.com" 
    
    0 讨论(0)
  • 2021-02-02 07:58
    >> "hey@mycorp.com".split("@").last
    => "mycorp.com"
    
    0 讨论(0)
  • 2021-02-02 07:59
        >>  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"
    
    0 讨论(0)
提交回复
热议问题