Skip to content

Instantly share code, notes, and snippets.

@sam
Created January 20, 2012 18:04
Show Gist options
  • Save sam/1648719 to your computer and use it in GitHub Desktop.
Save sam/1648719 to your computer and use it in GitHub Desktop.
module Harbor
module MailServers
class Sendmail < Abstract
attr_accessor :filter
def initialize(config = {})
@sendmail = config[:sendmail] || `which sendmail`.chomp
@filter = config[:delivery_address_filter]
@sender = config[:sender] || "bounce"
end
def deliver(message_or_messages)
messages = Array === message_or_messages ? message_or_messages : [message_or_messages]
messages.each do |message|
filter.apply(message) if filter
sendmail = ::IO.popen("#{@sendmail} -i -t -f#{@sender}", "w+")
sendmail.write(message.to_s)
sendmail.close_write
sendmail.close_read
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment