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) mail = Mail.new do delivery_method :smtp, smtp_opts to ['Mannetje ','Vrouwtje '] from 'SmartMeter ' 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 "

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