Class: Blogpost::Sendmail

Inherits:
Object
  • Object
show all
Defined in:
lib/blogpost/sendmail.rb

Class Method Summary collapse

Class Method Details

.post(opts = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/blogpost/sendmail.rb', line 3

def self.post(opts={})
  opts = Blogpost.options.merge(opts)
  opts[:port] = "25" unless opts.key?(:port)
  opts[:host] = "localhost" unless opts.key?(:host)
  opts[:user] = "[email protected]" unless opts.key?(:user)
  options = { :address              => opts[:host],
              :port                 => opts[:port],
              :enable_starttls_auto => false  }
  Mail.defaults do
    delivery_method :smtp, options
  end
  mail = Mail.new do
         to opts[:address]
       from opts[:user]
    subject opts[:title]
       body opts[:content]
content_type 'text/html; charset=UTF-8'
  end
  mail.deliver
end