### Home Classes Methods

### In Files

- lib/mail/patterns.rb
- lib/mail/envelope.rb
- lib/mail/part.rb
- lib/mail/field.rb
- lib/mail/mail.rb
- lib/mail/network.rb
- lib/mail/body.rb
- lib/mail/encodings/binary.rb
- lib/mail/encodings/quoted_printable.rb
- lib/mail/encodings/base64.rb
- lib/mail/encodings/8bit.rb
- lib/mail/encodings/transfer_encoding.rb
- lib/mail/encodings/7bit.rb
- lib/mail/check_delivery_params.rb
- lib/mail/header.rb
- lib/mail/multibyte/exceptions.rb
- lib/mail/multibyte/utils.rb
- lib/mail/version.rb
- lib/mail/field_list.rb
- lib/mail/utilities.rb
- lib/mail/attachments_list.rb
- lib/mail/matchers/has_sent_mail.rb
- lib/mail/network/retriever_methods/test_retriever.rb
- lib/mail/network/retriever_methods/pop3.rb
- lib/mail/network/retriever_methods/base.rb
- lib/mail/network/retriever_methods/imap.rb
- lib/mail/network/delivery_methods/smtp_connection.rb
- lib/mail/network/delivery_methods/test_mailer.rb
- lib/mail/network/delivery_methods/exim.rb
- lib/mail/network/delivery_methods/sendmail.rb
- lib/mail/network/delivery_methods/file_delivery.rb
- lib/mail/network/delivery_methods/smtp.rb
- lib/mail/fields.rb
- lib/mail/multibyte.rb
- lib/mail/elements.rb
- lib/mail/indifferent_hash.rb
- lib/mail/fields/return_path_field.rb
- lib/mail/fields/from_field.rb
- lib/mail/fields/unstructured_field.rb
- lib/mail/fields/to_field.rb
- lib/mail/fields/sender_field.rb
- lib/mail/fields/resent_bcc_field.rb
- lib/mail/fields/reply_to_field.rb
- lib/mail/fields/resent_from_field.rb
- lib/mail/fields/common/common_address.rb
- lib/mail/fields/common/common_message_id.rb
- lib/mail/fields/common/common_date.rb
- lib/mail/fields/common/common_field.rb
- lib/mail/fields/common/parameter_hash.rb
- lib/mail/fields/common/address_container.rb
- lib/mail/fields/resent_message_id_field.rb
- lib/mail/fields/optional_field.rb
- lib/mail/fields/content_id_field.rb
- lib/mail/fields/cc_field.rb
- lib/mail/fields/content_description_field.rb
- lib/mail/fields/date_field.rb
- lib/mail/fields/content_disposition_field.rb
- lib/mail/fields/mime_version_field.rb
- lib/mail/fields/message_id_field.rb
- lib/mail/fields/resent_to_field.rb
- lib/mail/fields/comments_field.rb
- lib/mail/fields/content_transfer_encoding_field.rb
- lib/mail/fields/bcc_field.rb
- lib/mail/fields/resent_sender_field.rb
- lib/mail/fields/received_field.rb
- lib/mail/fields/references_field.rb
- lib/mail/fields/resent_cc_field.rb
- lib/mail/fields/keywords_field.rb
- lib/mail/fields/structured_field.rb
- lib/mail/fields/subject_field.rb
- lib/mail/fields/in_reply_to_field.rb
- lib/mail/fields/resent_date_field.rb
- lib/mail/fields/content_type_field.rb
- lib/mail/fields/content_location_field.rb
- lib/mail/parsers/rfc2822.rb
- lib/mail/parsers/rfc2822_obsolete.rb
- lib/mail/parsers/content_location.rb
- lib/mail/parsers/envelope_from.rb
- lib/mail/parsers/rfc2045.rb
- lib/mail/parsers/content_disposition.rb
- lib/mail/parsers/received.rb
- lib/mail/parsers/message_ids.rb
- lib/mail/parsers/mime_version.rb
- lib/mail/parsers/content_transfer_encoding.rb
- lib/mail/parsers/content_type.rb
- lib/mail/parsers/phrase_lists.rb
- lib/mail/parsers/address_lists.rb
- lib/mail/parsers/date_time.rb
- lib/mail/elements/date_time_element.rb
- lib/mail/elements/phrase_list.rb
- lib/mail/elements/content_transfer_encoding_element.rb
- lib/mail/elements/envelope_from_element.rb
- lib/mail/elements/address_list.rb
- lib/mail/elements/received_element.rb
- lib/mail/elements/mime_version_element.rb
- lib/mail/elements/content_type_element.rb
- lib/mail/elements/content_disposition_element.rb
- lib/mail/elements/message_ids_element.rb
- lib/mail/elements/address.rb
- lib/mail/elements/content_location_element.rb
- lib/mail/parts_list.rb
- lib/mail/version_specific/ruby_1_9.rb
- lib/mail/version_specific/ruby_1_8.rb
- lib/mail.rb
- lib/load_parsers.rb

### Namespace

- MODULE Mail::AddressLists
- MODULE Mail::CheckDeliveryParams
- MODULE Mail::ContentDisposition
- MODULE Mail::ContentLocation
- MODULE Mail::ContentTransferEncoding
- MODULE Mail::ContentType
- MODULE Mail::DateTime
- MODULE Mail::Encodings
- MODULE Mail::EnvelopeFrom
- MODULE Mail::Matchers
- MODULE Mail::MessageIds
- MODULE Mail::MimeVersion
- MODULE Mail::Multibyte
- MODULE Mail::Patterns
- MODULE Mail::PhraseLists
- MODULE Mail::RFC2045
- MODULE Mail::RFC2822
- MODULE Mail::RFC2822Obsolete
- MODULE Mail::Received
- MODULE Mail::Utilities
- MODULE Mail::VERSION
- CLASS Mail::Address
- CLASS Mail::AddressContainer
- CLASS Mail::AddressListsParser
- CLASS Mail::AttachmentsList
- CLASS Mail::BccField
- CLASS Mail::Body
- CLASS Mail::CcField
- CLASS Mail::CommentsField
- CLASS Mail::ContentDescriptionField
- CLASS Mail::ContentDispositionField
- CLASS Mail::ContentDispositionParser
- CLASS Mail::ContentIdField
- CLASS Mail::ContentLocationField
- CLASS Mail::ContentLocationParser
- CLASS Mail::ContentTransferEncodingElement
- CLASS Mail::ContentTransferEncodingField
- CLASS Mail::ContentTransferEncodingParser
- CLASS Mail::ContentTypeField
- CLASS Mail::ContentTypeParser
- CLASS Mail::DateField
- CLASS Mail::DateTimeParser
- CLASS Mail::Envelope
- CLASS Mail::EnvelopeFromElement
- CLASS Mail::EnvelopeFromParser
- CLASS Mail::Exim
- CLASS Mail::Field
- CLASS Mail::FieldList
- CLASS Mail::FileDelivery
- CLASS Mail::FromField
- CLASS Mail::Header
- CLASS Mail::IMAP
- CLASS Mail::InReplyToField
- CLASS Mail::IndifferentHash
- CLASS Mail::KeywordsField
- CLASS Mail::MessageIdField
- CLASS Mail::MessageIdsElement
- CLASS Mail::MessageIdsParser
- CLASS Mail::MimeVersionElement
- CLASS Mail::MimeVersionField
- CLASS Mail::MimeVersionParser
- CLASS Mail::OptionalField
- CLASS Mail::POP3
- CLASS Mail::ParameterHash
- CLASS Mail::Part
- CLASS Mail::PartsList
- CLASS Mail::PhraseList
- CLASS Mail::PhraseListsParser
- CLASS Mail::RFC2045Parser
- CLASS Mail::RFC2822ObsoleteParser
- CLASS Mail::RFC2822Parser
- CLASS Mail::ReceivedElement
- CLASS Mail::ReceivedField
- CLASS Mail::ReceivedParser
- CLASS Mail::ReferencesField
- CLASS Mail::ReplyToField
- CLASS Mail::ResentBccField
- CLASS Mail::ResentCcField
- CLASS Mail::ResentDateField
- CLASS Mail::ResentFromField
- CLASS Mail::ResentMessageIdField
- CLASS Mail::ResentSenderField
- CLASS Mail::ResentToField
- CLASS Mail::Retriever
- CLASS Mail::ReturnPathField
- CLASS Mail::Ruby18
- CLASS Mail::Ruby19
- CLASS Mail::RubyVer
- CLASS Mail::SMTP
- CLASS Mail::SMTPConnection
- CLASS Mail::SenderField
- CLASS Mail::Sendmail
- CLASS Mail::StructuredField
- CLASS Mail::SubjectField
- CLASS Mail::TestMailer
- CLASS Mail::TestRetriever
- CLASS Mail::ToField
- CLASS Mail::UnstructuredField

### Methods

- ::all
- ::compile_parser
- ::connection
- ::defaults
- ::delete_all
- ::deliver
- ::delivery_method
- ::eager_autoload!
- ::find
- ::find_and_delete
- ::first
- ::inform_interceptors
- ::inform_observers
- ::last
- ::new
- ::random_tag
- ::read
- ::read_from_string
- ::register_autoload
- ::register_interceptor
- ::register_observer
- ::retriever_method

### Files

- TODO.rdoc
- VERSION

### Class/Module Index

Quicksearch

- Mail
- Mail::Address
- Mail::AddressContainer
- Mail::AddressLists
- Mail::AddressLists::PrimaryAddress0
- Mail::AddressLists::PrimaryAddress1
- Mail::AddressListsParser
- Mail::AttachmentsList
- Mail::BccField
- Mail::Body
- Mail::CcField
- Mail::CheckDeliveryParams
- Mail::CommentsField
- Mail::ContentDescriptionField
- Mail::ContentDisposition
- Mail::ContentDisposition::ContentDisposition0
- Mail::ContentDisposition::ContentDisposition1
- Mail::ContentDisposition::ContentDisposition2
- Mail::ContentDisposition::DispositionType0
- Mail::ContentDisposition::DispositionType1
- Mail::ContentDisposition::Parameter0
- Mail::ContentDisposition::Parameter1
- Mail::ContentDisposition::Value0
- Mail::ContentDispositionField
- Mail::ContentDispositionParser
- Mail::ContentIdField
- Mail::ContentLocation
- Mail::ContentLocation::Location0
- Mail::ContentLocation::Primary0
- Mail::ContentLocationField
- Mail::ContentLocationParser
- Mail::ContentTransferEncoding
- Mail::ContentTransferEncoding::Primary0
- Mail::ContentTransferEncodingElement
- Mail::ContentTransferEncodingField
- Mail::ContentTransferEncodingParser
- Mail::ContentType
- Mail::ContentType::CompositeType0
- Mail::ContentType::CompositeType1
- Mail::ContentType::ContentType0
- Mail::ContentType::ContentType1
- Mail::ContentType::ContentType2
- Mail::ContentType::DiscreteType0
- Mail::ContentType::DiscreteType1
- Mail::ContentType::DiscreteType2
- Mail::ContentType::DiscreteType3
- Mail::ContentType::DiscreteType4
- Mail::ContentType::Parameter0
- Mail::ContentType::Parameter1
- Mail::ContentType::Value0
- Mail::ContentTypeField
- Mail::ContentTypeParser
- Mail::DateField
- Mail::DateTime
- Mail::DateTime::Primary0
- Mail::DateTime::Primary1
- Mail::DateTimeParser
- Mail::Encodings
- Mail::Encodings::Base64
- Mail::Encodings::Binary
- Mail::Encodings::EightBit
- Mail::Encodings::QuotedPrintable
- Mail::Encodings::SevenBit
- Mail::Encodings::TransferEncoding
- Mail::Envelope
- Mail::EnvelopeFrom
- Mail::EnvelopeFrom::CtimeDate0
- Mail::EnvelopeFrom::Primary0
- Mail::EnvelopeFromElement
- Mail::EnvelopeFromParser
- Mail::Exim
- Mail::Field
- Mail::Field::FieldError
- Mail::FieldList
- Mail::FileDelivery
- Mail::FromField
- Mail::Header
- Mail::IMAP
- Mail::InReplyToField
- Mail::IndifferentHash
- Mail::KeywordsField
- Mail::Matchers
- Mail::Matchers::HasSentEmailMatcher
- Mail::MessageIdField
- Mail::MessageIds
- Mail::MessageIds::Primary0
- Mail::MessageIdsElement
- Mail::MessageIdsParser
- Mail::MimeVersion
- Mail::MimeVersion::Version0
- Mail::MimeVersion::Version1
- Mail::MimeVersionElement
- Mail::MimeVersionField
- Mail::MimeVersionParser
- Mail::Multibyte
- Mail::Multibyte::EncodingError
- Mail::OptionalField
- Mail::POP3
- Mail::ParameterHash
- Mail::Part
- Mail::PartsList
- Mail::Patterns
- Mail::PhraseList
- Mail::PhraseLists
- Mail::PhraseLists::PrimaryPhrase0
- Mail::PhraseListsParser
- Mail::RFC2045
- Mail::RFC2045::CustomXToken0
- Mail::RFC2045Parser
- Mail::RFC2822
- Mail::RFC2822::AddrSpec0
- Mail::RFC2822::Address0
- Mail::RFC2822::AddressList0
- Mail::RFC2822::AddressList1
- Mail::RFC2822::AngleAddr0
- Mail::RFC2822::Atom0
- Mail::RFC2822::CFWS0
- Mail::RFC2822::CFWS1
- Mail::RFC2822::Comment0
- Mail::RFC2822::Comment1
- Mail::RFC2822::Date0
- Mail::RFC2822::DateTime0
- Mail::RFC2822::DateTime1
- Mail::RFC2822::Day0
- Mail::RFC2822::DayOfWeek0
- Mail::RFC2822::DomainLiteral0
- Mail::RFC2822::DomainLiteral1
- Mail::RFC2822::DomainText0
- Mail::RFC2822::DomainText1
- Mail::RFC2822::DotAtom0
- Mail::RFC2822::DotAtomText0
- Mail::RFC2822::FWS0
- Mail::RFC2822::FWS1
- Mail::RFC2822::Group0
- Mail::RFC2822::Hour0
- Mail::RFC2822::ItemName0
- Mail::RFC2822::ItemName1
- Mail::RFC2822::LocalDotAtom0
- Mail::RFC2822::LocalDotAtomText0
- Mail::RFC2822::Mailbox0
- Mail::RFC2822::MailboxList0
- Mail::RFC2822::MailboxList1
- Mail::RFC2822::MailboxListGroup0
- Mail::RFC2822::MessageIds0
- Mail::RFC2822::MessageIds1
- Mail::RFC2822::Minute0
- Mail::RFC2822::Month0
- Mail::RFC2822::MsgId0
- Mail::RFC2822::MsgIdDomainText0
- Mail::RFC2822::MsgIdDomainText1
- Mail::RFC2822::MsgIdDotAtomText0
- Mail::RFC2822::MsgIdValue0
- Mail::RFC2822::NameAddr0
- Mail::RFC2822::NameValList0
- Mail::RFC2822::NameValList1
- Mail::RFC2822::NameValList2
- Mail::RFC2822::NameValPair0
- Mail::RFC2822::NoFoldLiteral0
- Mail::RFC2822::NoFoldQuote0
- Mail::RFC2822::Path0
- Mail::RFC2822::PhraseList0
- Mail::RFC2822::PhraseList1
- Mail::RFC2822::QuotedDomain0
- Mail::RFC2822::QuotedPair0
- Mail::RFC2822::QuotedString0
- Mail::RFC2822::QuotedString1
- Mail::RFC2822::Received0
- Mail::RFC2822::Return0
- Mail::RFC2822::Second0
- Mail::RFC2822::Time0
- Mail::RFC2822::TimeOfDay0
- Mail::RFC2822::TimeOfDay1
- Mail::RFC2822::Year0
- Mail::RFC2822::Zone0
- Mail::RFC2822Obsolete
- Mail::RFC2822Obsolete::ObsAddrList0
- Mail::RFC2822Obsolete::ObsAddrList1
- Mail::RFC2822Obsolete::ObsAngleAddr0
- Mail::RFC2822Obsolete::ObsBcc0
- Mail::RFC2822Obsolete::ObsCc0
- Mail::RFC2822Obsolete::ObsComments0
- Mail::RFC2822Obsolete::ObsDay0
- Mail::RFC2822Obsolete::ObsDay1
- Mail::RFC2822Obsolete::ObsDayOfWeek0
- Mail::RFC2822Obsolete::ObsDomain0
- Mail::RFC2822Obsolete::ObsDomain1
- Mail::RFC2822Obsolete::ObsDomainList0
- Mail::RFC2822Obsolete::ObsDomainList1
- Mail::RFC2822Obsolete::ObsFWS0
- Mail::RFC2822Obsolete::ObsFWS1
- Mail::RFC2822Obsolete::ObsFrom0
- Mail::RFC2822Obsolete::ObsHour0
- Mail::RFC2822Obsolete::ObsHour1
- Mail::RFC2822Obsolete::ObsInReplyTo0
- Mail::RFC2822Obsolete::ObsKeywords0
- Mail::RFC2822Obsolete::ObsLocalPart0
- Mail::RFC2822Obsolete::ObsLocalPart1
- Mail::RFC2822Obsolete::ObsMboxList0
- Mail::RFC2822Obsolete::ObsMboxList1
- Mail::RFC2822Obsolete::ObsMessageId0
- Mail::RFC2822Obsolete::ObsMinute0
- Mail::RFC2822Obsolete::ObsMinute1
- Mail::RFC2822Obsolete::ObsMonth0
- Mail::RFC2822Obsolete::ObsOptional0
- Mail::RFC2822Obsolete::ObsOrigDate0
- Mail::RFC2822Obsolete::ObsPhraseList0
- Mail::RFC2822Obsolete::ObsPhraseList1
- Mail::RFC2822Obsolete::ObsQp0
- Mail::RFC2822Obsolete::ObsReceived0
- Mail::RFC2822Obsolete::ObsReferences0
- Mail::RFC2822Obsolete::ObsReplyTo0
- Mail::RFC2822Obsolete::ObsResentBcc0
- Mail::RFC2822Obsolete::ObsResentCc0
- Mail::RFC2822Obsolete::ObsResentDate0
- Mail::RFC2822Obsolete::ObsResentFrom0
- Mail::RFC2822Obsolete::ObsResentMid0
- Mail::RFC2822Obsolete::ObsResentRply0
- Mail::RFC2822Obsolete::ObsResentSend0
- Mail::RFC2822Obsolete::ObsResentTo0
- Mail::RFC2822Obsolete::ObsReturn0
- Mail::RFC2822Obsolete::ObsRoute0
- Mail::RFC2822Obsolete::ObsSecond0
- Mail::RFC2822Obsolete::ObsSecond1
- Mail::RFC2822Obsolete::ObsSender0
- Mail::RFC2822Obsolete::ObsSubject0
- Mail::RFC2822Obsolete::ObsText0
- Mail::RFC2822Obsolete::ObsText1
- Mail::RFC2822Obsolete::ObsTo0
- Mail::RFC2822Obsolete::ObsYear0
- Mail::RFC2822Obsolete::ObsYear1
- Mail::RFC2822ObsoleteParser
- Mail::RFC2822Parser
- Mail::Received
- Mail::Received::Primary0
- Mail::ReceivedElement
- Mail::ReceivedField
- Mail::ReceivedParser
- Mail::ReferencesField
- Mail::ReplyToField
- Mail::ResentBccField
- Mail::ResentCcField
- Mail::ResentDateField
- Mail::ResentFromField
- Mail::ResentMessageIdField
- Mail::ResentSenderField
- Mail::ResentToField
- Mail::Retriever
- Mail::ReturnPathField
- Mail::Ruby18
- Mail::Ruby19
- Mail::RubyVer
- Mail::SMTP
- Mail::SMTPConnection
- Mail::SenderField
- Mail::Sendmail
- Mail::StructuredField
- Mail::SubjectField
- Mail::TestMailer
- Mail::TestRetriever
- Mail::ToField
- Mail::UnstructuredField
- Mail::Utilities
- Mail::VERSION
- Net
- Net::SMTP
- Object
- String

No matching classes.

# Mail

# Mail Envelope

The Envelope class provides a field for the first line in an mbox file, that looks like "From mikel@test.lindsaar.net DATETIME"

This envelope class reads that line, and turns it into an Envelope.from and Envelope.date for your use.

encoding: utf-8

This is an almost cut and paste from ActiveSupport v3.0.6, copied in here so that Mail itself does not depend on ActiveSupport to avoid versioning conflicts

# Comments Field

The Comments field inherits from UnstructuredField and handles the Comments: header field in the email.

Sending comments to a mail message will instantiate a Mail::Field object that has a CommentsField as its field type.

An email header can have as many comments fields as it wants. There is no upper limit, the comments field is also optional (that is, no comment is needed)

## Examples:

    mail = Mail.new
    mail.comments = 'This is a comment'
    mail.comments    #=> 'This is a comment'
    mail[:comments]  #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
    mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
    mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4

    mail.comments = "This is another comment"
    mail[:comments].map { |c| c.to_s }
    #=> ['This is a comment', "This is another comment"]

trace = [return]

    1*received

return = "Return-Path:" path CRLF

path = ([CFWS] "<" ([CFWS] / addr-spec) ">" [CFWS]) /

    obs-path

received = "Received:" name-val-list ";" date-time CRLF

name-val-list = [CFWS] [name-val-pair *(CFWS name-val-pair)]

name-val-pair = item-name CFWS item-value

item-name = ALPHA *(["-"] (ALPHA / DIGIT))

item-value = 1*angle-addr / addr-spec /

    atom / domain / msg-id

keywords = "Keywords:" phrase *("," phrase) CRLF

subject = "Subject:" unstructured CRLF

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

Autogenerated from a Treetop grammar. Edits may be lost.

This file loads up the parsers for mail to use. It also will attempt to compile parsers if they don't exist.

It also only uses the compiler if we are running the SPEC suite

### Constants

RubyVer

### Public Class Methods

all(*args, &block) click to toggle source

Receive all emails from the default retriever See Mail::Retriever for a complete documentation.

    # File lib/mail/mail.rb, line 169
    def self.all(*args, &block)
      retriever_method.all(*args, &block)
    end

compile_parser(parser) click to toggle source

    # File lib/load_parsers.rb, line 8
    def self.compile_parser(parser)
      require 'treetop/compiler'
      Treetop.load(File.join(File.dirname(__FILE__)) + "/mail/parsers/#{parser}")
    end

connection(&block) click to toggle source

    # File lib/mail/mail.rb, line 189
    def Mail.connection(&block)
      retriever_method.connection(&block)
    end

defaults(&block) click to toggle source

Sets the default delivery method and retriever method for all new Mail objects. The delivery_method and retriever_method default to :smtp and :pop3, with defaults set.

So sending a new email, if you have an SMTP server running on localhost is as easy as:

    Mail.deliver do
      to      'mikel@test.lindsaar.net'
      from    'bob@test.lindsaar.net'
      subject 'hi there!'
      body    'this is a body'
    end

If you do not specify anything, you will get the following equivalent code set in every new mail object:

    Mail.defaults do
      delivery_method :smtp, { :address              => "localhost",
                               :port                 => 25,
                               :domain               => 'localhost.localdomain',
                               :user_name            => nil,
                               :password             => nil,
                               :authentication       => nil,
                               :enable_starttls_auto => true  }

      retriever_method :pop3, { :address             => "localhost",
                                :port                => 995,
                                :user_name           => nil,
                                :password            => nil,
                                :enable_ssl          => true }
    end

    Mail.delivery_method.new  #=> Mail::SMTP instance
    Mail.retriever_method.new #=> Mail::POP3 instance

Each mail object inherits the default set in Mail.delivery_method, however, on a per email basis, you can override the method:

    mail.delivery_method :sendmail

Or you can override the method and pass in settings:

    mail.delivery_method :sendmail, { :address => 'some.host' }

You can also just modify the settings:

    mail.delivery_settings = { :address => 'some.host' }

The passed in hash is just merged against the defaults with `merge!` and the result assigned the mail object. So the above example will change only the :address value of the global smtp_settings to be 'some.host', keeping all other values

    # File lib/mail/mail.rb, line 104
    def self.defaults(&block)
      Configuration.instance.instance_eval(&block)
    end

delete_all(*args, &block) click to toggle source

Delete all emails from the default retriever See Mail::Retriever for a complete documentation.

    # File lib/mail/mail.rb, line 180
    def self.delete_all(*args, &block)
      retriever_method.delete_all(*args, &block)
    end

deliver(*args, &block) click to toggle source

Send an email using the default configuration. You do need to set a default configuration first before you use self.deliver, if you don't, an appropriate error will be raised telling you to.

If you do not specify a delivery type, SMTP will be used.

    Mail.deliver do
     to 'mikel@test.lindsaar.net'
     from 'ada@test.lindsaar.net'
     subject 'This is a test email'
     body 'Not much to say here'
    end

You can also do:

    mail = Mail.read('email.eml')
    mail.deliver!

And your email object will be created and sent.

    # File lib/mail/mail.rb, line 137
    def self.deliver(*args, &block)
      mail = self.new(args, &block)
      mail.deliver
      mail
    end

delivery_method() click to toggle source

Returns the delivery method selected, defaults to an instance of Mail::SMTP

    # File lib/mail/mail.rb, line 109
    def self.delivery_method
      Configuration.instance.delivery_method
    end

eager_autoload!() click to toggle source

This runs through the autoload list and explictly requires them for you. Useful when running mail in a threaded process.

Usage:

    require 'mail'
    Mail.eager_autoload!

    # File lib/mail.rb, line 60
    def self.eager_autoload!
      @@autoloads.each { |_,path| require(path) }
    end

find(*args, &block) click to toggle source

Find emails from the default retriever See Mail::Retriever for a complete documentation.

    # File lib/mail/mail.rb, line 145
    def self.find(*args, &block)
      retriever_method.find(*args, &block)
    end

find_and_delete(*args, &block) click to toggle source

Finds and then deletes retrieved emails from the default retriever See Mail::Retriever for a complete documentation.

    # File lib/mail/mail.rb, line 151
    def self.find_and_delete(*args, &block)
      retriever_method.find_and_delete(*args, &block)
    end

first(*args, &block) click to toggle source

Receive the first email(s) from the default retriever See Mail::Retriever for a complete documentation.

    # File lib/mail/mail.rb, line 157
    def self.first(*args, &block)
      retriever_method.first(*args, &block)
    end

inform_interceptors(mail) click to toggle source

    # File lib/mail/mail.rb, line 227
    def self.inform_interceptors(mail)
      @@delivery_interceptors.each do |interceptor|
        interceptor.delivering_email(mail)
      end
    end

inform_observers(mail) click to toggle source

    # File lib/mail/mail.rb, line 221
    def self.inform_observers(mail)
      @@delivery_notification_observers.each do |observer|
        observer.delivered_email(mail)
      end
    end

last(*args, &block) click to toggle source

Receive the first email(s) from the default retriever See Mail::Retriever for a complete documentation.

    # File lib/mail/mail.rb, line 163
    def self.last(*args, &block)
      retriever_method.last(*args, &block)
    end

new(*args, &block) click to toggle source

Allows you to create a new Mail::Message object.

You can make an email via passing a string or passing a block.

For example, the following two examples will create the same email message:

Creating via a string:

    string = "To: mikel@test.lindsaar.net\r\n"
    string << "From: bob@test.lindsaar.net\r\n"
    string << "Subject: This is an email\r\n"
    string << "\r\n"
    string << "This is the body"
    Mail.new(string)

Or creating via a block:

    message = Mail.new do
      to 'mikel@test.lindsaar.net'
      from 'bob@test.lindsaar.net'
      subject 'This is an email'
      body 'This is the body'
    end

Or creating via a hash (or hash like object):

    message = Mail.new({:to => 'mikel@test.lindsaar.net',
                        'from' => 'bob@test.lindsaar.net',
                        :subject => 'This is an email',
                        :body => 'This is the body' })

Note, the hash keys can be strings or symbols, the passed in object does not need to be a hash, it just needs to respond to :each_pair and yield each key value pair.

As a side note, you can also create a new email through creating a Mail::Message object directly and then passing in values via string, symbol or direct method calls. See Mail::Message for more information.

    mail = Mail.new
    mail.to = 'mikel@test.lindsaar.net'
    mail[:from] = 'bob@test.lindsaar.net'
    mail['subject'] = 'This is an email'
    mail.body = 'This is the body'

    # File lib/mail/mail.rb, line 48
    def self.new(*args, &block)
      Message.new(args, &block)
    end

read(filename) click to toggle source

Reads in an email message from a path and instantiates it as a new Mail::Message

    # File lib/mail/mail.rb, line 174
    def self.read(filename)
      self.new(File.open(filename, 'rb') { |f| f.read })
    end

read_from_string(mail_as_string) click to toggle source

Instantiates a new Mail::Message using a string

    # File lib/mail/mail.rb, line 185
    def Mail.read_from_string(mail_as_string)
      Mail.new(mail_as_string)
    end

register_autoload(name, path) click to toggle source

    # File lib/mail.rb, line 48
    def self.register_autoload(name, path)
      @@autoloads[name] = path
      autoload(name, path)
    end

register_interceptor(interceptor) click to toggle source

You can register an object to be given every mail object that will be sent, before it is sent. So if you want to add special headers or modify any email that gets sent through the Mail library, you can do so.

Your object needs to respond to a single method delivering_email(mail) which receives the email that is about to be sent. Make your modifications directly to this object.

    # File lib/mail/mail.rb, line 215
    def self.register_interceptor(interceptor)
      unless @@delivery_interceptors.include?(interceptor)
        @@delivery_interceptors << interceptor
      end
    end

register_observer(observer) click to toggle source

You can register an object to be informed of every email that is sent through this method.

Your object needs to respond to a single method delivered_email(mail) which receives the email that is sent.

    # File lib/mail/mail.rb, line 202
    def self.register_observer(observer)
      unless @@delivery_notification_observers.include?(observer)
        @@delivery_notification_observers << observer
      end
    end

retriever_method() click to toggle source

Returns the retriever method selected, defaults to an instance of Mail::POP3

    # File lib/mail/mail.rb, line 114
    def self.retriever_method
      Configuration.instance.retriever_method
    end

### Protected Class Methods

random_tag() click to toggle source

    # File lib/mail/mail.rb, line 235
    def self.random_tag
      t = Time.now
      sprintf('%x%x_%x%x%d%x',
              t.to_i, t.tv_usec,
              $$, Thread.current.object_id.abs, self.uniq, rand(255))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.