Skip to content

jeremyevans/simple_mailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

= simple_mailer

simple_mailer is a very simple email library for ruby, with testing
support.  It just uses ruby's standard net/smtp library to send out
the emails.  Configuration is limited to setting the server that
the email is sent to (defaults to localhost).  Testing support is
limited to appending the emails that would have been sent to an
array.

simple_mailer can be installed with:

    sudo gem install simple_mailer

Source is available at github:
http://github.com/jeremyevans/simple_mailer

== Usage

There is no required configuration, you can use simple_mailer
immediately:

  require 'simple_mailer'
  SimpleMailer.send_email('[email protected]', '[email protected]', 'Subject',
    'Body', 'HeaderKey'=>'HeaderValue')
  
Or, you can include the SimpleMailer module in other classes:

  class Mailer
    include SimpleMailer

    def initialize(subject, body)
      @subject = subject
      @body = body
      self.smtp_server = 'smtp.example.com'
    end

    def email(from, to)
      send_email(from, to, @subject, @body)
    end
  end
  Mailer.new('Subject', 'Body').email('[email protected]', '[email protected]')

== Special Headers

There are four special headers that simple_mailer processes:

:smtp_to :: Override the actual SMTP recipients without modifying
            the message.
:smtp_from :: Override the actual STMP sender without modifying
              the message.
:cc :: Add a recipient to the message and include a CC header
       with that recipient.
:bcc :: Add an recipient to the message without including that
        information in the message headers.

All other headers are used verbatim in the message.

== Configuration

You can pass in options just like with the Mail gem.

  SimpleMailer.smtp_settings.update(
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "localhost",
    :user_name => "bob",
    :password => "secret",
    :authentication => :plain,
  )

== Testing

Testing support is probably the main reason to use simple_mailer over
using net/smtp directly.  After you enter test mode, emails you send
are available via the emails_sent option:

  SimpleMailer.test_mode!
  SimpleMailer.emails_sent # []
  SimpleMailer.send_email('[email protected]', '[email protected]', 'S', 'B')
  SimpleMailer.emails_sent # [[message, '[email protected]', '[email protected]']]

== Author

Jeremy Evans ([email protected])

About

Simple email library with testing support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages