Module: BBMB::Util::Mail
- Defined in:
- lib/bbmb/util/mail.rb
Class Method Summary collapse
- .notify_confirmation_error(order) ⇒ Object
- .notify_debug(subject, body) ⇒ Object
- .notify_error(error) ⇒ Object
- .notify_inject_error(order, opts = {}) ⇒ Object
- .send_confirmation(order) ⇒ Object
- .send_order(order) ⇒ Object
- .send_request(email, organisation, body) ⇒ Object
- .sendmail(my_body, my_subject, from_addr, to_addr, cc_addrs = [], my_reply_to = nil) ⇒ Object
Class Method Details
.notify_confirmation_error(order) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bbmb/util/mail.rb', line 12 def Mail.notify_confirmation_error(order) config = BBMB.config if to = config.confirm_error_to customer = order.customer from = config.confirm_error_from cc = config.confirm_error_cc subject = config.confirm_error_subject % customer.customer_id body = config.confirm_error_body % customer.customer_id Mail.sendmail body, subject, from, to, cc end end |
.notify_debug(subject, body) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/bbmb/util/mail.rb', line 23 def Mail.notify_debug(subject, body) config = BBMB.config from = config.mail_order_from to = config.error_recipients subject = sprintf "%s: %s", BBMB.config.name, subject Mail.sendmail(body, subject, from, to) end |
.notify_error(error) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/bbmb/util/mail.rb', line 30 def Mail.notify_error(error) config = BBMB.config from = config.mail_order_from to = config.error_recipients subject = sprintf "%s: %s", BBMB.config.name, error. body = [ error.class, error., error.backtrace ].flatten.join("\n") Mail.sendmail(body, subject, from, to) end |
.notify_inject_error(order, opts = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/bbmb/util/mail.rb', line 39 def Mail.notify_inject_error(order, opts={}) config = BBMB.config if to = config.inject_error_to customer = order.customer from = config.inject_error_from cc = config.inject_error_cc subject = config.inject_error_subject % [ order.order_id, opts[:customer_name] || customer.customer_id, ] body = config.inject_error_body % [ opts[:customer_name] || customer.customer_id, order.commit_time.strftime('%d.%m.%Y %H:%M:%S'), customer.customer_id, ] Mail.sendmail body, subject, from, to, cc end end |
.send_confirmation(order) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/bbmb/util/mail.rb', line 91 def Mail.send_confirmation(order) config = BBMB.config ## there are two switches that determine whether a confirmation is sent out: # application-wide: mail_confirm_reply_to must be configured reply_to = config.mail_confirm_reply_to or return nil # per-customer: order_confirmation must be checked order.customer.order_confirmation or return nil to = order.customer.email or return notify_confirmation_error(order) body = config.mail_confirm_body or return nil date = order.commit_time.strftime("%d.%m.%Y") parts = [] config.mail_confirm_lines.collect do |line| content = order.collect do |pos| sprintf line, pos.quantity, pos.description, pos.price_qty, pos.total end parts.push date, content.join("\n"), order.total if vtotal = order.total_incl_vat parts.push vtotal end end from = config.mail_confirm_from subject = config.mail_confirm_subject % order.order_id body = sprintf *parts Mail.sendmail(body, subject, from, to, config.mail_confirm_cc, reply_to) end |
.send_order(order) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/bbmb/util/mail.rb', line 118 def Mail.send_order(order) config = BBMB.config from = config.mail_order_from to = config.mail_order_to cc = config.mail_order_cc subject = config.mail_order_subject % order.order_id body = order.to_target_format Mail.sendmail(body, subject, from, to, cc) end |
.send_request(email, organisation, body) ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/bbmb/util/mail.rb', line 127 def Mail.send_request(email, organisation, body) config = BBMB.config from = config.mail_request_from to = config.mail_request_to cc = config.mail_request_cc subject = config.mail_request_subject % organisation Mail.sendmail("", subject, from, to, cc, email) end |
.sendmail(my_body, my_subject, from_addr, to_addr, cc_addrs = [], my_reply_to = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bbmb/util/mail.rb', line 57 def Mail.sendmail(my_body, my_subject, from_addr, to_addr, cc_addrs=[], my_reply_to = nil) config = BBMB.config config.mail_suppress_sending = true if defined?(::MiniTest) if config.mail_suppress_sending msg = [ "#{__FILE__}:#{__LINE__} Suppress sending mail with subject: #{my_subject}", " from #{from_addr} to: #{to_addr} cc: #{cc_addrs} reply_to: #{my_reply_to}", my_body.to_s[0..10240] ] puts msg unless defined?(::MiniTest) ::Mail.defaults do delivery_method :test end else puts "Mail.sendmail #{config.smtp_server} #{config.smtp_port} #{config.smtp_helo} smtp_user: #{ config.smtp_user} #{ config.smtp_pass} #{ config.smtp_authtype}" puts "Mail.sendmail from #{from_addr} to #{to_addr} cc #{cc_addrs} message: #{my_body.class}" return if to_addr == nil ::Mail.defaults do = { :address => config.smtp_server, :port => config.smtp_port, :domain => config.smtp_domain, :user_name => config.smtp_user, :password => config.smtp_pass, :authentication => 'plain', :enable_starttls_auto => true } delivery_method :smtp, end end ::Mail.deliver do from from_addr to to_addr cc cc_addrs reply_to (my_reply_to ? my_reply_to : from_addr) subject my_subject body my_body end end |