Sha256: 3e136963fa3f212d8d930c084209ab0651e0de00940524c0ee8acb7419e47379
Contents?: true
Size: 1.5 KB
Versions: 2
Compression:
Stored size: 1.5 KB
Contents
require 'net/smtp' begin require 'mailfactory' rescue LoadError puts "You need to install the mailfactory gem to use Merb::Mailer" MERB_LOGGER.fatal "You need to install the mailfactory gem to use Merb::Mailer" end module Merb class Mailer shared_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.0.9 | lib/merb/merb_mailer.rb |
merb-0.1.0 | lib/merb/merb_mailer.rb |