Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
MailBuilder is a simple library for building RFC compliant MIME emails.
Ruby
Branch: master
Pull request Compare This branch is 5 commits ahead of bernerdschaefer:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.rvmrc
.travis.yml
Doubleshot
Doubleshot.lock
MIT-LICENSE
README.md

README.md

MailBuilder

Build Status

MailBuilder is a library for building RFC compliant MIME messages, with support for text and HTML emails, as well as attachments.

Basic Usage

require 'rubygems'
require 'mail_builder'

mail = MailBuilder.new
mail.to = "joe@example.com"
mail.text = "Body"

sendmail = IO.popen("#{`which sendmail`.chomp} -i -t", "w+")
sendmail.puts mail
sendmail.close

or

require 'net/smtp'

Net::SMTP.start("smtp.address.com", 25) do |smtp|
  smtp.send_message(mail.to_s, mail.from, mail.to)
end

Advantages

One of the key advantages to using MailBuilder over other libraries (such as MailFactory) is that costly operations - generating boundaries, reading attached files, etc. - are delayed until the physical message is built (by calling build or to_s).

This gives you the freedom to generate many thousands of emails with almost no time-cost. The emails could then be passed to some external system - DRb, database - for final delivery.

10_000.times do
  mail = MailBuilder.new('to' => 'joe@example.com')
  mail.html = View.new("mailers/large_mailer")
  mail.attach("large_file.pdf")

  ExternalMailServer.send!(mail)
end

The external process would then build the email, at which point the view would be rendered and attachments read, while the local process would complete in very little (on my machine, sub-second) time.

Something went wrong with that request. Please try again.