using rails 3 mail

How do you get the name part from the front field of an email using the new rails 3 mail ?

In actual email there is a from field like this :

<From: rogger rabbit <>>

If i do mail.from.first i get part but how do it get the name bit ie. rogger rabbit ?

thanks a lot Rick


Looking at mail-2.2.17/lib/mail/elements/address.rb i found this:

a ='Mikel Lindsaar (My email address) <>')
a.format       #=> 'Mikel Lindsaar <> (My email address)'
a.address      #=> ''
a.display_name #=> 'Mikel Lindsaar'
a.local        #=> 'mikel'
a.domain       #=> ''
a.comments     #=> ['My email address']
a.to_s         #=> 'Mikel Lindsaar <> (My email address)'

Try with something like mail[:from].addrs.collect {|a| a.display_name}

You might want to try the decoded method:


After tearing my hair out all morning, I finally got this to work with:


Where "message" is a mail object you might be iterating through.

Beware: If the sender doesn't have a display name, this will be nil.

Need Your Help

Loading javascript file asynchronously

javascript ajax asynchronous

I am trying to make an asynchronous call to a server in the following way

Writing a persistent perl script

linux perl bash unix

I am trying to write a persistent/cached script. The code would look something like this: