Skip to content

Instantly share code, notes, and snippets.

@marzdgzmn
Created September 6, 2018 09:20
Show Gist options
  • Save marzdgzmn/fa7501a880686b282eeddb194123f5be to your computer and use it in GitHub Desktop.
Save marzdgzmn/fa7501a880686b282eeddb194123f5be to your computer and use it in GitHub Desktop.
class EmailNotification < Base
def send(message, time)
@message = Formatter.format(message, time)
Pony.mail({
:to => RiseMirrorApp::Config.notification_email,
:from => "mirror@#{Socket.gethostname}",
:via => :smtp,
:via_options => {
:address => 'aspmx.l.google.com',
:port => 25,
# :user_name => 'username',
# :password => 'password',
# :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => Socket.gethostname
},
:subject => "[#{Socket.gethostname}]Sync @ #{time.strftime("[%Y-%m-%d]%e, %H:%M")}",
:html_body => "#{@message}"
})
end
end
class Formatter
def self.format(message, time)
xm = Builder::XmlMarkup.new(:indent => 8)
xm.table {
xm.tr { "Sync result status for #{time.strftime("%m-%d-%Y @ %H:%M:%S")} run" }
xm.tr { message[0].keys.each {|key| xm.th(key)}}
message.each do |mirror|
xm.tr { [xm.td(mirror['name']), xm.td(mirror['last_successful_sync']),
xm.td(mirror['start_sync']), xm.td(mirror['end_sync']),
xm.td(mirror['status']), xm.td(mirror['total_bandwidth'])] }
end
}
xm
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment