Sha256: a65b533f0f7b297408fbb18f43f1ad5aa7f673908b753d7785dcbee3dc98734e
Contents?: true
Size: 1.51 KB
Versions: 2
Compression:
Stored size: 1.51 KB
Contents
begin require 'mailfactory' require 'net/smtp' rescue LoadError puts "You need to install the mailfactory gem to use Merb::Mailer" MERB_LOGGER.warn "You need to install the mailfactory gem to use Merb::Mailer" end module Merb class Mailer class_inheritable_accessor :config def sendmail sendmail = IO.popen("sendmail #{@mail.to}", 'w+') sendmail.puts @mail.to_s sendmail.close end # :plain, :login, or :cram_md5 def net_smtp Net::SMTP.start(config[:host], config[:port].to_i, config[:domain], config[:user], config[:pass], (config[:auth].intern||:plain)) { |smtp| smtp.send_message(@mail.to_s, @mail.from, @mail.to) } end def deliver! config == :sendmail ? sendmail : net_smtp end def initialize(o={}) self.config = :sendmail if config.nil? @mail = returning MailFactory.new() do |m| m.to = o[:to] m.from = o[:from] m.subject = o[:subject] m.text = o[:body] m.html = o[:html] if o[:html] end end end end =begin m = Merb::Mailer.new :to => 'foo@bar.com', :from => 'bar@foo.com', :subject => 'Welcome to whatever!', :body => partial(:sometemplate) m.deliver! Merb::Mailer.config = { :host=>'smtp.yourserver.com', :port=>'25', :user=>'user', :pass=>'pass', :auth=>:plain # :plain, :login, or :cram_md5, default :plain } =end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
merb-0.3.0 | lib/merb/merb_mailer.rb |
merb-0.3.1 | lib/merb/merb_mailer.rb |