Module: YDIM::Mail
- Defined in:
- lib/ydim/mail.rb
Class Method Summary collapse
- .body(config, debitor, invoice) ⇒ Object
- .send_invoice(config, invoice, sort_args = {}) ⇒ Object
- .send_reminder(config, autoinvoice) ⇒ Object
Class Method Details
.body(config, debitor, invoice) ⇒ Object
19 20 21 22 |
# File 'lib/ydim/mail.rb', line 19 def Mail.body(config, debitor, invoice) salutation = config.salutation[debitor.salutation.to_s] sprintf(config.mail_body, salutation, debitor.contact, invoice.description) end |
.send_invoice(config, invoice, sort_args = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ydim/mail.rb', line 23 def Mail.send_invoice(config, invoice, sort_args={}) debitor = invoice.debitor invoice_subject = sprintf('Rechnung %s #%i, %s', debitor.name, invoice.unique_id, invoice.description) @mail = ::Mail.new @mail.to = debitor.email @mail.cc = debitor.emails_cc @mail.bcc = config.mail_recipients @mail.from = config.mail_from @mail.subject = invoice_subject @mail.body = body(config, debitor, invoice) @mail.add_file(:filename => sprintf("%i.pdf", invoice.unique_id), :content => invoice.to_pdf(sort_args)) @mail.deliver (@mail.to + @mail.cc + @mail.bcc).flatten rescue Timeout::Error retries ||= 3 if retries > 0 sleep 3 - retries retries -= 1 retry else raise end end |
.send_reminder(config, autoinvoice) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ydim/mail.rb', line 47 def Mail.send_reminder(config, autoinvoice) debitor = autoinvoice.debitor reminder_subject = autoinvoice.reminder_subject.to_s.strip reminder_subject.gsub! %r{<year>\s*}, '' reminder_subject.gsub! %r{\s*</year>}, '' mail_body = autoinvoice.reminder_body.to_s.strip mail_body.gsub! %r{<invoice>\s*}, '' mail_body.gsub! %r{\s*</invoice>}, '' return if reminder_subject.empty? || mail_body.empty? @mail = ::Mail.new @mail.to = debitor.email @mail.cc = debitor.emails_cc @mail.from = config.mail_from @mail.subject = reminder_subject @mail.body = mail_body @mail.deliver end |