class Mail::Address
- Mail::Address
- Reference
- Object
Overview
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) [email protected]') a.format #=> 'Mikel Lindsaar [email protected] (My email address)' a.address #=> '[email protected]' a.display_name #=> 'Mikel Lindsaar' a.local #=> 'mikel' a.domain #=> 'test.lindsaar.net' a.comments #=> ['My email address'] a.to_s #=> 'Mikel Lindsaar [email protected] (My email address)'
Defined in:
mail/elements/address.crConstructors
Instance Method Summary
-
#address(output_type = :decode)
Returns the address that is in the address itself.
-
#address=(value)
Provides a way to assign an address to an already made Mail::Address object.
- #comments
- #decoded
-
#display_name(output_type = :decode)
Returns the display name of the email address passed in.
-
#display_name=(str)
Provides a way to assign a display name to an already made Mail::Address object.
-
#domain(output_type = :decode)
Returns the domain part (the right hand side of the @ sign in the email address) of the address
- #encoded
-
#format(output_type = :decode)
Returns a correctly formatted address for the email going out.
- #group
-
#inspect
Shows the Address object basic details, including the Address a = Address.new('Mikel (My email) [email protected]') a.inspect #=> "#<Mail::Address:14184910 Address: |Mikel [email protected] (My email)| >"
-
#local(output_type = :decode)
Returns the local part (the left hand side of the @ sign in the email address) of the address
-
#name
Sometimes an address will not have a display name, but might have the name as a comment field after the address.
-
#raw
Returns the raw input of the passed in string, this is before it is passed by the parser.
-
#to_s
Returns the format of the address, or returns nothing
Constructor Detail
Instance Method Detail
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) [email protected]') a.address #=> '[email protected]'
Provides a way to assign an address to an already made Mail::Address object.
a = Address.new a.address = 'Mikel Lindsaar (My email address) [email protected]' a.address #=> '[email protected]'
Returns the display name of the email address passed in.
a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.display_name #=> 'Mikel Lindsaar'
Provides a way to assign a display name to an already made Mail::Address object.
a = Address.new a.address = '[email protected]' a.display_name = 'Mikel Lindsaar' a.format #=> 'Mikel Lindsaar [email protected]'
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) [email protected]') a.domain #=> 'test.lindsaar.net'
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) [email protected]') a.format #=> 'Mikel Lindsaar [email protected] (My email address)'
Shows the Address object basic details, including the Address a = Address.new('Mikel (My email) [email protected]') a.inspect #=> "#<Mail::Address:14184910 Address: |Mikel [email protected] (My email)| >"
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) [email protected]') a.local #=> 'mikel'
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('[email protected] (Mikel Lindsaar)') a.name #=> 'Mikel Lindsaar'
Returns the format of the address, or returns nothing
a = Address.new('Mikel Lindsaar (My email address) [email protected]') a.format #=> 'Mikel Lindsaar [email protected] (My email address)'