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
# 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)
body = "From: \#{opts[:user]}\nTo: \#{opts[:address]}\nSubject: \#{opts[:title]}\nDate: \#{Time::now.strftime(\"%a, %d %b %Y %X %z\")}\nContent-Type: text/html; charset=UTF-8\n\n\#{opts[:content]}\n"
  Net::SMTP.start(opts[:host], opts[:port]) do |smtp|
    smtp.send_mail body, opts[:user], opts[:address]
  end
end