emailer

Emailer is a collection of utility classes for sending emails using an existing SMTP service. I personally only use it with AuthSMTP, and it’s not been extensively tested. Use at your own risk.

Notice that you’ll need to install TMail to use emailer. I’ve not included it as a dependency as the gem does not currently install with Ruby 1.9, there are, however, patched versions out there.

I apologize in advance for the lack of documentation. There is little going on in the code, and the interface should be easy enough for anyone to figure out with a minute to glance at the code. Here’s a taste:

Basic use

smtp = Emailer::AuthsmtpFacade.new :username => '[username]', :pasword => '[password]', :domain => 'localhost'
smtp.open do
  smtp.send_text(
      :from => '[email protected]',
      :to => '[email protected]',
      :subject => 'Thanks',
      :body => 'Mail body.'
    )
end

Bulk messages

queue = Emailer::MailQueue.new smtp
queue.add(
    :from => '[email protected]',
    :to => '[email protected]',
    :subject => 'Thanks',
    :body => 'Mail body.'
  ) { |success, mail| puts "Sent mail to #{mail[:to]}..." }
queue.process

Testing using webrat

Add middleware to render emails for webrat

  Emailer::SmtpFacade.default = Emailer::MockSmtpFacade.new
  config.middleware.use "Emailer::TestingMiddleware"

Then you can get the url to the last email sent using

  Emailer::SmtpFacade.default.last_email_sent_url

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 Erik Hansson. See LICENSE for details.