Email tariffs daily

This commit is contained in:
Aart van Halteren
2022-10-23 12:23:08 +02:00
parent d799468869
commit c7aa6e5d92
2 changed files with 47 additions and 1 deletions

View 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