Module: ODDB::Util::Mail

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

Class Method Summary collapse

Class Method Details

.notify_admins(subject, lines) ⇒ Object



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

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_user, recipients)
end

.notify_invoice(invoice) ⇒ Object



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
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/oddb/util/mail.rb', line 29

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]),
  ]
  instructed = false
  invoice.items.each { |item|
    case item.type
    when :download
      unless instructed
        parts.push lnf.lookup(:download_mail_body)
        parts.push lnf.lookup(:download_mail_instr)
      end
      instructed = true
      parts.push lnf._event_url(:collect,
                                [:invoice, invoice.id,
                                 :file, Download.compressed_download(item)])
    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])
    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))
    end
  }
  mpart.body = parts.join("\n\n")
  sendmail(mpart, config.mail_invoice_smtp, recipients)
end

.sendmail(mpart, from, recipients) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/oddb/util/mail.rb', line 75

def Mail.sendmail(mpart, from, recipients)
  config = ODDB.config
  Net::SMTP.start(config.smtp_server, config.smtp_port,
                  config.smtp_domain, config.smtp_user, config.smtp_pass,
                  config.smtp_authtype) do |smtp|
    recipients.each { |recipient|
      smtp.sendmail(mpart.to_s, from, recipient)
    }
  end
end