module Mail

def self.all(*args, &block)

See Mail::Retriever for a complete documentation.
Receive all emails from the default retriever
def self.all(*args, &block)
  retriever_method.all(*args, &block)
end

def self.defaults(&block)

mail.delivery_method :smtp, :address => 'some.host'

Or you can override the method and pass in settings:

mail.delivery_method :smtp

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

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

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

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

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

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

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

set.
The delivery_method and retriever_method default to :smtp and :pop3, with defaults
Sets the default delivery method and retriever method for all new Mail objects.
def self.defaults(&block)
  Configuration.instance.instance_eval(&block)
end

def self.delete_all(*args, &block)

See Mail::Retriever for a complete documentation.
Delete all emails from the default retriever
def self.delete_all(*args, &block)
  retriever_method.delete_all(*args, &block)
end

def self.deliver(*args, &block)

And your email object will be created and sent.

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

You can also do:

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

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

error will be raised telling you to.
configuration first before you use self.deliver, if you don't, an appropriate
Send an email using the default configuration. You do need to set a default
def self.deliver(*args, &block)
  mail = self.new(args, &block)
  mail.deliver
  mail
end

def self.delivery_method

Returns the delivery method selected, defaults to an instance of Mail::SMTP
def self.delivery_method
  Configuration.instance.delivery_method
end

def self.eager_autoload!

Mail.eager_autoload!
require 'mail'

Usage:

Useful when running mail in a threaded process.
This runs through the autoload list and explictly requires them for you.
def self.eager_autoload!
  @@autoloads.each { |_,path| require(path) }
end

def self.find(*args, &block)

See Mail::Retriever for a complete documentation.
Find emails from the default retriever
def self.find(*args, &block)
  retriever_method.find(*args, &block)
end

def self.find_and_delete(*args, &block)

See Mail::Retriever for a complete documentation.
Finds and then deletes retrieved emails from the default retriever
def self.find_and_delete(*args, &block)
  retriever_method.find_and_delete(*args, &block)
end

def self.first(*args, &block)

See Mail::Retriever for a complete documentation.
Receive the first email(s) from the default retriever
def self.first(*args, &block)
  retriever_method.first(*args, &block)
end

def self.inform_interceptors(mail)

def self.inform_interceptors(mail)
  @@delivery_interceptors.each do |interceptor|
    interceptor.delivering_email(mail)
  end
end

def self.inform_observers(mail)

def self.inform_observers(mail)
  @@delivery_notification_observers.each do |observer|
    observer.delivered_email(mail)
  end
end

def self.last(*args, &block)

See Mail::Retriever for a complete documentation.
Receive the first email(s) from the default retriever
def self.last(*args, &block)
  retriever_method.last(*args, &block)
end

def self.new(*args, &block)

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

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

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

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

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

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

Or creating via a block:

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

Creating via a string:

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

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

Allows you to create a new Mail::Message object.
def self.new(*args, &block)
  Message.new(args, &block)
end

def self.random_tag

def self.random_tag
  t = Time.now
  sprintf(RANDOM_TAG,
          t.to_i, t.tv_usec,
          $$, Thread.current.object_id.abs, self.uniq, rand(255))
end

def self.read(filename)

Reads in an email message from a path and instantiates it as a new Mail::Message
def self.read(filename)
  self.new(File.open(filename, 'rb') { |f| f.read })
end

def self.register_autoload(name, path)

def self.register_autoload(name, path)
  @@autoloads[name] = path
  autoload(name, path)
end

def self.register_interceptor(interceptor)

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

email that gets sent through the Mail library, you can do so.
before it is sent. So if you want to add special headers or modify any
You can register an object to be given every mail object that will be sent,
def self.register_interceptor(interceptor)
  unless @@delivery_interceptors.include?(interceptor)
    @@delivery_interceptors << interceptor
  end
end

def self.register_observer(observer)

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

this method.
You can register an object to be informed of every email that is sent through
def self.register_observer(observer)
  unless @@delivery_notification_observers.include?(observer)
    @@delivery_notification_observers << observer
  end
end

def self.retriever_method

Returns the retriever method selected, defaults to an instance of Mail::POP3
def self.retriever_method
  Configuration.instance.retriever_method
end

def self.something_random

def self.something_random
  (Thread.current.object_id * rand(255) / Time.now.to_f).to_s.slice(-3..-1).to_i
end

def self.uniq

def self.uniq
  @@uniq += 1
end

def self.unregister_interceptor(interceptor)

without it.
Unregister the given interceptor, allowing mail to resume operations
def self.unregister_interceptor(interceptor)
  @@delivery_interceptors.delete(interceptor)
end

def self.unregister_observer(observer)

without it.
Unregister the given observer, allowing mail to resume operations
def self.unregister_observer(observer)
  @@delivery_notification_observers.delete(observer)
end