Module: ODDB::Util::Mail

Defined in:
lib/oddb/util/mail.rb

Class Method Summary collapse

Class Method Details

.notify_admins(subject, lines) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/oddb/util/mail.rb', line 13

def Mail.notify_admins(subject, lines)
  config = ODDB.config
  recipients = config.admins
  mpart = RMail::Message.new
  header = mpart.header
  header.to = recipients
  header.from = config.mail_from
  header.subject = subject
  header.date = Time.now
  header.add('Content-Type', 'text/plain', nil, 
             'charset' => config.mail_charset)
  mpart.body = lines.join("\n")
  sendmail(mpart, config.smtp_from, recipients)
end

.notify_invoice(invoice) ⇒ 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
54
55
56
57
58
59
60
61
62
# File 'lib/oddb/util/mail.rb', line 27

def Mail.notify_invoice(invoice)
  config = ODDB.config
  lnf = Html::Util::LookandfeelStub.new('de')
  mpart = RMail::Message.new
  header = mpart.header
  header.to = recipient = invoice.yus_name
  header.from = config.mail_invoice_from
  header.subject = lnf.lookup(:poweruser_mail_subject)
  header.date = Time.now
  header.add('Content-Type', 'text/plain', nil, 
             'charset' => config.mail_charset)
  recipients = [recipient].concat config.debug_recipients
  yus = Util::Yus.get_preferences(recipient, :salutation, :name_last)
  parts = [
    lnf.lookup(:poweruser_mail_salut, lnf.lookup(yus[:salutation]), 
               yus[:name_last]),
  ]
  invoice.items.each { |item|
    case item.type
    when :poweruser
      days = item.quantity
      duration = (days == 1) \
               ? lnf.lookup(:days_one_genitive) \
               : lnf.lookup(:days_genitive, days)
      parts.push lnf.lookup(:poweruser_mail_body)
      parts.push lnf.lookup(:poweruser_mail_instr,
                            duration, lnf._event_url(:login))
    when :export
      parts.push lnf.lookup(:download_export_mail_body)
      parts.push lnf.lookup(:download_export_mail_instr)
      parts.push lnf._event_url(:collect, [:invoice, invoice.id])
    end
  }
  mpart.body = parts.join("\n\n")
  sendmail(mpart, config.mail_invoice_smtp, recipients)
end

.sendmail(mpart, from, recipients) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/oddb/util/mail.rb', line 63

def Mail.sendmail(mpart, from, recipients)
  smtp = Net::SMTP.new(ODDB.config.smtp_server)
  smtp.start {
    recipients.each { |recipient|
      smtp.sendmail(mpart.to_s, from, recipient)
    }
  }
end