Added real content to email body
This commit is contained in:
@@ -1,38 +1,50 @@
|
||||
require "mail"
|
||||
|
||||
class ReadingsMailer
|
||||
OPTS = { :address => "mail.van-halteren.net",
|
||||
:port => 465,
|
||||
:domain => 'van-halteren.net',
|
||||
:user_name => 'aart@van-halteren.net',
|
||||
:password => '',
|
||||
:authentication => 'plain',
|
||||
:enable_ssl => true}
|
||||
|
||||
OPTS_NO_SSL_VERIFY = {
|
||||
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
||||
|
||||
SSL_OPTS = {
|
||||
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
||||
}
|
||||
|
||||
# IMAP_OPTS = { :address => "mail.van-halteren.net",
|
||||
# :port => 993,
|
||||
# :user_name => 'aart@van-halteren.net',
|
||||
# :password => 'XXXXX',
|
||||
# :openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
|
||||
# :enable_ssl => true
|
||||
# }
|
||||
|
||||
#
|
||||
# Class methods
|
||||
#
|
||||
class << self
|
||||
def deliver
|
||||
|
||||
mail = Mail.new do
|
||||
delivery_method :smtp, OPTS_NO_SSL_VERIFY
|
||||
to 'aart@van-halteren.net'
|
||||
def deliver
|
||||
# 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")
|
||||
|
||||
# Fetch today's usage
|
||||
usage_today = Reading.diff_on(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 'First multipart email sent with Mail'
|
||||
subject 'SmartMeter report'
|
||||
|
||||
text_part do
|
||||
body 'This is plain text'
|
||||
body "Summary for #{Date.today}\n
|
||||
-------------------------------\n\n
|
||||
Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}\n
|
||||
Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}\n
|
||||
Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}\n
|
||||
"
|
||||
end
|
||||
|
||||
html_part do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
body '<h1>This is HTML</h1>'
|
||||
end
|
||||
# html_part do
|
||||
# content_type 'text/html; charset=UTF-8'
|
||||
# body '<h1>This is HTML</h1>'
|
||||
# end
|
||||
end
|
||||
|
||||
mail.deliver!
|
||||
|
||||
Reference in New Issue
Block a user