Skip to content

Commit

Permalink
Adding Exim as it's own delivery manager for Issue 70
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikel Lindsaar committed Jan 14, 2012
1 parent 9fe9fc1 commit 632c05e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
18 changes: 13 additions & 5 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,14 @@ mail.delivery_method :sendmail
mail.deliver
```

Exim requires it's own delivery manager, and can be used like so:

```ruby
mail.delivery_method :exim, :location => "/usr/bin/exim"

mail.deliver
```

### Getting emails from a pop server:

You can configure Mail to receive email using <code>retriever_method</code>
Expand Down Expand Up @@ -340,7 +348,7 @@ content type and has a boundary defined.
### Testing and extracting attachments
```ruby
mail.attachments.each do | attachment |
# Attachments is an AttachmentsList object containing a
# Attachments is an AttachmentsList object containing a
# number of Part objects
if (attachment.content_type.start_with?('image/'))
# extracting images for example...
Expand Down Expand Up @@ -522,7 +530,7 @@ end
@round_tripped_mail.attachments.length #=> 1
@round_tripped_mail.attachments.first.filename #=> 'myfile.pdf'
```
See "Testing and extracting attachments" above for more details.
See "Testing and extracting attachments" above for more details.

Using Mail with Testing or Spec'ing Libraries
---------------------------------------------
Expand Down Expand Up @@ -581,13 +589,13 @@ describe "sending an email" do
it { should have_sent_email.to('mike1@me.com') }
# can specify a list of recipients...
it { should have_sent_email.to(['mike1@me.com', 'mike2@me.com']) }
it { should have_sent_email.to(['mike1@me.com', 'mike2@me.com']) }
# ...or chain recipients together
it { should have_sent_email.to('mike1@me.com').to('mike2@me.com') }
it { should have_sent_email.to('mike1@me.com').to('mike2@me.com') }
it { should have_sent_email.with_subject('testing') }
it { should have_sent_email.with_body('hello') }
# Can match subject or body with a regex
Expand Down
8 changes: 5 additions & 3 deletions lib/mail/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
require 'singleton'

module Mail

# The Configuration class is a Singleton used to hold the default
# configuration for all Mail objects.
#
#
# Each new mail object gets a copy of these values at initialization
# which can be overwritten on a per mail object basis.
class Configuration
Expand All @@ -33,6 +33,8 @@ def lookup_delivery_method(method)
Mail::SMTP
when :sendmail
Mail::Sendmail
when :exim
Mail::Exim
when :file
Mail::FileDelivery
when :smtp_connection
Expand All @@ -48,7 +50,7 @@ def retriever_method(method = nil, settings = {})
return @retriever_method if @retriever_method && method.nil?
@retriever_method = lookup_retriever_method(method).new(settings)
end

def lookup_retriever_method(method)
case method
when nil
Expand Down
1 change: 1 addition & 0 deletions lib/mail/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Mail
autoload :SMTP, 'mail/network/delivery_methods/smtp'
autoload :FileDelivery, 'mail/network/delivery_methods/file_delivery'
autoload :Sendmail, 'mail/network/delivery_methods/sendmail'
autoload :Exim, 'mail/network/delivery_methods/exim'
autoload :SMTPConnection, 'mail/network/delivery_methods/smtp_connection'
autoload :TestMailer, 'mail/network/delivery_methods/test_mailer'

Expand Down
20 changes: 20 additions & 0 deletions lib/mail/network/delivery_methods/exim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Mail

class Exim < Sendmail

def deliver!(mail)
envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
return_path = "-f \"#{envelope_from.to_s.shellescape}\"" if envelope_from
arguments = [settings[:arguments], return_path].compact.join(" ")
self.class.call(settings[:location], arguments, mail)
end

def self.call(path, arguments, mail)
IO.popen("#{path} #{arguments}", "w+") do |io|
io.puts mail.encoded.to_lf
io.flush
end
end

end
end
12 changes: 9 additions & 3 deletions spec/mail/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Mail::Configuration do

describe "network configurations" do

it "should be available from the Mail.defaults method" do
Mail.defaults { delivery_method :smtp, { :address => 'some.host' } }
Mail.delivery_method.settings[:address].should == 'some.host'
Expand All @@ -14,13 +14,19 @@
Mail.delivery_method.class.should == Mail::Sendmail
Mail.delivery_method.settings[:location].should == "/usr/bin/sendmail"
end


it "should configure exim" do
Mail.defaults { delivery_method :exim, :location => "/usr/bin/exim" }
Mail.delivery_method.class.should == Mail::Exim
Mail.delivery_method.settings[:location].should == "/usr/bin/exim"
end

it "should configure an open SMTP connection" do
smtp = Net::SMTP.start('127.0.0.1', 25)
Mail.defaults { delivery_method :smtp_connection, {:connection => smtp} }
Mail.delivery_method.class.should == Mail::SMTPConnection
Mail.delivery_method.smtp.should == smtp
end

end
end

0 comments on commit 632c05e

Please sign in to comment.