Email tariffs daily
This commit is contained in:
46
app/helpers/TariffsMailer.rb
Normal file
46
app/helpers/TariffsMailer.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
require "mail"
|
||||
|
||||
class TariffsMailer
|
||||
|
||||
SSL_OPTS = {
|
||||
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Class methods
|
||||
#
|
||||
class << self
|
||||
def deliver(date)
|
||||
# Read SMTP options from smtp.yml
|
||||
smtp_opts = YAML::load(File.open('config/smtp.yml')).symbolize_keys
|
||||
smtp_opts.merge!(SSL_OPTS) if smtp_opts[:ssl] && smtp_opts[:ssl_verify_mode].eql?("none")
|
||||
|
||||
# Create png file
|
||||
c = Cost.new
|
||||
c.easy_energy_tariff_barplot(Date.today)
|
||||
|
||||
mail = Mail.new do
|
||||
delivery_method :smtp, smtp_opts
|
||||
to 'a.t.van.halteren@vu.nl'
|
||||
from 'SmartMeter <aart@van-halteren.net>'
|
||||
subject "EasyEnergy tariffs for #{date}"
|
||||
|
||||
text_part do
|
||||
body "Tariffs for #{date}\n"
|
||||
end
|
||||
|
||||
html_part do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body "<h1>Tariffs for #{date}"
|
||||
end
|
||||
|
||||
# add attachment
|
||||
filename = "easy_tariff_%s.png" % date.strftime("%F")
|
||||
add_file :filename => filename, :content => File.read("plots/%s" % filename)
|
||||
end
|
||||
|
||||
mail.deliver!
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user