class

Mail::Address

Inherits Reference < Object

Mail::Address handles all email addresses in Mail. It takes an email address string and parses it, breaking it down into its component parts and allowing you to get the address, comments, display name, name, local part, domain part and fully formatted address.

Mail::Address requires a correctly formatted email address per RFC2822 or RFC822. It handles all obsolete versions including obsolete domain routing on the local part.

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.format #=> 'Mikel Lindsaar mikel@test.lindsaar.net (My email address)' a.address #=> 'mikel@test.lindsaar.net' a.display_name #=> 'Mikel Lindsaar' a.local #=> 'mikel' a.domain #=> 'test.lindsaar.net' a.comments #=> ['My email address'] a.to_s #=> 'Mikel Lindsaar mikel@test.lindsaar.net (My email address)'

Constructors

new(value = nil)
Source

Instance methods

address(output_type = :decode)

Returns the address that is in the address itself. That is, the local@domain string, without any angle brackets or the like.

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.address #=> 'mikel@test.lindsaar.net'

Source
address=(value)

Provides a way to assign an address to an already made Mail::Address object.

a = Address.new a.address = 'Mikel Lindsaar (My email address) mikel@test.lindsaar.net' a.address #=> 'mikel@test.lindsaar.net'

Source
comments
Source
decoded
Source
display_name(output_type = :decode)

Returns the display name of the email address passed in.

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.display_name #=> 'Mikel Lindsaar'

Source
display_name=(str)

Provides a way to assign a display name to an already made Mail::Address object.

a = Address.new a.address = 'mikel@test.lindsaar.net' a.display_name = 'Mikel Lindsaar' a.format #=> 'Mikel Lindsaar mikel@test.lindsaar.net'

Source
domain(output_type = :decode)

Returns the domain part (the right hand side of the @ sign in the email address) of the address

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.domain #=> 'test.lindsaar.net'

Source
encoded
Source
format(output_type = :decode)

Returns a correctly formatted address for the email going out. If given an incorrectly formatted address as input, Mail::Address will do its best to format it correctly. This includes quoting display names as needed and putting the address in angle brackets etc.

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.format #=> 'Mikel Lindsaar mikel@test.lindsaar.net (My email address)'

Source
group
Source
inspect

Shows the Address object basic details, including the Address a = Address.new('Mikel (My email) mikel@test.lindsaar.net') a.inspect #=> "#<Mail::Address:14184910 Address: |Mikel mikel@test.lindsaar.net (My email)| >"

Source
local(output_type = :decode)

Returns the local part (the left hand side of the @ sign in the email address) of the address

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.local #=> 'mikel'

Source
name

Sometimes an address will not have a display name, but might have the name as a comment field after the address. This returns that name if it exists.

a = Address.new('mikel@test.lindsaar.net (Mikel Lindsaar)') a.name #=> 'Mikel Lindsaar'

Source
raw

Returns the raw input of the passed in string, this is before it is passed by the parser.

Source
to_s

Returns the format of the address, or returns nothing

a = Address.new('Mikel Lindsaar (My email address) mikel@test.lindsaar.net') a.format #=> 'Mikel Lindsaar mikel@test.lindsaar.net (My email address)'

Source