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