Class: Mailer
- Inherits:
-
Object
- Object
- Mailer
- Defined in:
- lib/backupper/mailer.rb
Class Method Summary collapse
Class Method Details
.body(report) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/backupper/mailer.rb', line 27 def self.body(report) b = [] report.each do |k, data| s = '' if data[:error] s << "❌ #{k}\n" s << '=' * 80 << "\n" s << "Backup FAILED!\n" s << " error: #{data[:error]}\n" b << s else s << "️✅ #{k}\n" s << '=' * 80 << "\n" s << "Backup SUCCESS!\n" s << " dump size: #{data[:size]} MB\n" s << " time: #{data[:time]} seconds\n" s << " dump saved in: #{data[:path]}\n" if data[:extra_copy] s << " extra copy in: #{data[:extra_copy]}\n" else s << " no extra copy has been made\n" end b << s end end return "Report for backups (#{Time.now})\n\n#{b.join("\n\n")}" end |
.send(from:, to:, password:, report:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/backupper/mailer.rb', line 5 def self.send(from:, to:, password:, report:) = { address: 'smtp.gmail.com', port: 587, user_name: from, password: password, authentication: 'plain', enable_starttls_auto: true } Mail.defaults do delivery_method :smtp, end Mail.deliver do to to from from subject Mailer.subject(report) body Mailer.body(report) end end |
.subject(report) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/backupper/mailer.rb', line 55 def self.subject(report) errors = report.select{|k, v| v[:error]}.size icon = '✅' icon = '⚠️' if errors > 0 icon = '❌' if errors == report.size return "[Backupper] #{report.size-errors}/#{report.size} backups successfully completed #{icon}" end |