Adds attachment to email
This commit is contained in:
@@ -28,6 +28,9 @@ class ReadingsMailer
|
|||||||
c = Cost.new
|
c = Cost.new
|
||||||
oxxio_cost = c.oxxio_energy_cost(date.to_s,usage_today[:total_kwh_consumed_high]-usage_today[:total_kwh_produced_high], usage_today[:total_kwh_consumed_low]-usage_today[:total_kwh_produced_low])
|
oxxio_cost = c.oxxio_energy_cost(date.to_s,usage_today[:total_kwh_consumed_high]-usage_today[:total_kwh_produced_high], usage_today[:total_kwh_consumed_low]-usage_today[:total_kwh_produced_low])
|
||||||
easy_cost = c.easy_energy_cost_barplot(date) # side effect: generates a PNG
|
easy_cost = c.easy_energy_cost_barplot(date) # side effect: generates a PNG
|
||||||
|
# rounding
|
||||||
|
oxxio_cost = oxxio_cost.round(2)
|
||||||
|
easy_cost = easy_cost.round(2)
|
||||||
|
|
||||||
mail = Mail.new do
|
mail = Mail.new do
|
||||||
delivery_method :smtp, smtp_opts
|
delivery_method :smtp, smtp_opts
|
||||||
@@ -53,9 +56,13 @@ class ReadingsMailer
|
|||||||
"<p>Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}</p>" +
|
"<p>Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}</p>" +
|
||||||
"<p>Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}</p>" +
|
"<p>Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}</p>" +
|
||||||
"</br>" +
|
"</br>" +
|
||||||
"<p>kWH cost (Oxxio): EUR #{ oxxio_cost} </p>" +
|
"<p>kWH cost (Oxxio): <b>EUR #{ oxxio_cost} </b></p>" +
|
||||||
"<p>kWH cost (EasyEnergy): EUR #{ easy_cost} </p>"
|
"<p>kWH cost (EasyEnergy): <b>EUR #{ easy_cost} </b></p>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add attachment
|
||||||
|
filename = "easy_cost_%s.png" % date.strftime("%F")
|
||||||
|
add_file :filename => filename, :content => File.read("plots/%s" % filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
mail.deliver!
|
mail.deliver!
|
||||||
|
|||||||
Reference in New Issue
Block a user