Class: SimpleBackup::Utils::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_backup/utils/mailer.rb

Constant Summary collapse

@@logger =
Logger.instance

Instance Method Summary collapse

Constructor Details

#initializeMailer

Returns a new instance of Mailer.



9
10
11
12
13
14
# File 'lib/simple_backup/utils/mailer.rb', line 9

def initialize()
  @to = []
  @cc = []
  @bcc = []
  @hostname = Socket.gethostbyname(Socket.gethostname).first
end

Instance Method Details

#bcc(bcc) ⇒ Object



32
33
34
# File 'lib/simple_backup/utils/mailer.rb', line 32

def bcc(bcc)
  @bcc << bcc
end

#cc(cc) ⇒ Object



28
29
30
# File 'lib/simple_backup/utils/mailer.rb', line 28

def cc(cc)
  @cc << cc
end

#from(from) ⇒ Object



20
21
22
# File 'lib/simple_backup/utils/mailer.rb', line 20

def from(from)
  @from = from
end

#sendObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/simple_backup/utils/mailer.rb', line 36

def send
  @@logger.info "Setting sender to: #{@from}"
  from = @from
  @@logger.scope_start :info, "Adding recipients:"
  to = @to
  to.each do |mail|
    @@logger.info "to: #{mail}"
  end
  cc = @cc
  cc.each do |mail|
    @@logger.info "cc: #{mail}"
  end
  bcc = @bcc
  bcc.each do |mail|
    @@logger.info "bcc: #{mail}"
  end
  @@logger.scope_end

  @subject_prefix += '[FAILED]' if SimpleBackup.status == :failed

  subject = "%s Backup %s for %s" % [@subject_prefix, TIMESTAMP, @hostname]
  @@logger.debug "Subject: #{subject}"

  body = get_body

  mail = Mail.new do
    from    from
    to      to
    cc      cc
    bcc     bcc
    subject subject.strip
    body    body
  end

  mail.delivery_method :sendmail
  @@logger.debug "Setting delivery method to sendmail"

  mail.deliver
  @@logger.info "Notification sent"
end

#subject_prefix(prefix) ⇒ Object



16
17
18
# File 'lib/simple_backup/utils/mailer.rb', line 16

def subject_prefix(prefix)
  @subject_prefix = prefix
end

#to(to) ⇒ Object



24
25
26
# File 'lib/simple_backup/utils/mailer.rb', line 24

def to(to)
  @to << to
end