Rob Lacey

Brighton, UK -

Software Engineer specialising in Ruby on Rails. I do occasional freelance work, I love working for SARD JV Ltd, they are awesome and give me my pocket money every month. By all means dangle a carrot.

Accessing TMail::Mail headers

While trying to test TMail::Mail#to header, despite setting the address in full with the recipients name I kept getting just the address back

>> t =
=> #<TMail::Mail port=#<TMail::StringPort:id=0x3ff92369be30> bodyport=nil>
>> = "RobL <>"
=> "RobL <>"
=> [""]

It seems there are a few ways of grabbing the to address back, to just returns an array of e-mail addresses. to_addrs or [‘to’] actually return the full “to” address.

>> t.to_addrs
=> [#<TMail::Address>
>> t.to_addrs.first.to_s
=> "RobL <>"
>> t['to'].first.to_s
=> "RobL <>"