dcidev_mailer 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4c888484deeed90b4688c4b671c3dcce1c0cd2e6c8246ef60a7779cfb73bd9f
4
- data.tar.gz: 4d90779c9e75604a863487d060db02b8170de0cbdd2785e61478d4b3c20cf0e9
3
+ metadata.gz: ed94880843b2769154af5f080cd85ecedbe73889f50da7d2f8d93745140264df
4
+ data.tar.gz: fe43144786157d05b25b80a1bfe2a6efd7b5c5396846a5c466018fd57e6a4a06
5
5
  SHA512:
6
- metadata.gz: 9eca49e59d46f4bb88c6870c3bcd5bb468d6c8ce44c3f346dfbfc29cada557840fb8f3f7af5f65478ee38cda297063e9725b298b7aef423dc37e342870ec9b5a
7
- data.tar.gz: 53a043bb683096d6f2d992d49da00c636beb7548753fe3676bbd71a81dea5830f8284e8677657c128a47d7754768f7650d4de2ecc1124f9260f35096ef32bbd4
6
+ metadata.gz: d022a4bfd340978d3a1b652a33cb9153b477eb98ad85a449599c87578f32b64cf5079b3ce4aed2ff06e6dd13158b32357e68c5f992424275b6819da61f60b3ab
7
+ data.tar.gz: 83d280862d6434e7c46151fcb17eaf90cec0ae77a630092c3ab785f7ec9f8f1f4afba346448db557a678fdbf684dd5a1789b2d500748d4dd275448e8e79d5cf4
data/README.md CHANGED
@@ -27,42 +27,46 @@ MAILER_SMTP_TLS=
27
27
 
28
28
  Add this to `config/initializer/mailer.rb`
29
29
  ```ruby
30
- ActionMailer::Base.delivery_method = :smtp
30
+ ActionMailer::Base.delivery_method =: smtp
31
31
 
32
32
  # change it to your helper class name
33
- ActionMailer::Base.add_delivery_method :mandrill_mailer, MandrillMailer
34
-
35
- # uncomment if neccessary
36
- smtp_settings = {
37
- address: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_ADDRESS'] : ENV["MAILER_SMTP_ADDRESS"],
38
- # authentication: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? 'plain' : nil,
39
- domain: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_DOMAIN'] : ENV["MAILER_SMTP_DOMAIN"],
40
- enable_starttls_auto: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
41
- tls: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
42
- # password: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PASSWORD'] : ENV["MAILER_SMTP_PASSWORD"],
43
- port: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PORT'] : ENV["MAILER_SMTP_PORT"],
44
- # user_name: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_USERNAME'] : ENV["MAILER_SMTP_USERNAME"],
45
- # openssl_verify_mode: "none",}
46
-
47
- if ENV["USE_MANDRILL_MAILER"].to_i == 1
48
- smtp_settings[:authentication] = 'plain'
49
- smtp_settings[:password] = ENV['MANDRILL_SMTP_PASSWORD']
50
- smtp_settings[:user_name] = ENV['MANDRILL_SMTP_USERNAME']
51
- end
52
-
53
- ActionMailer::Base.smtp_settings = smtp_settings
54
-
55
- ActionMailer::Base.default_url_options = { :host => ENV["BASE_URL_FE"] }
56
- ActionMailer::Base.register_preview_interceptor(ActionMailer::InlinePreviewInterceptor)
57
-
58
- # Don't care if the mailer can't send.
59
- ActionMailer::Base.raise_delivery_errors = true
60
- ActionMailer::Base.perform_deliveries = true
61
- ActionMailer::Base.perform_caching = false
62
-
63
- MandrillMailer.configure do |config|
64
- config.api_key = ENV["MANDRILL_SMTP_PASSWORD"]
65
- config.deliver_later_queue_name = :default
33
+ ActionMailer::Base.add_delivery_method: mandrill_mailer, MandrillMailer
34
+
35
+ # uncomment
36
+ if neccessary
37
+ smtp_settings = {
38
+ address: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_ADDRESS'] : ENV["MAILER_SMTP_ADDRESS"],
39
+ # authentication: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? 'plain' : nil,
40
+ domain: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_DOMAIN'] : ENV["MAILER_SMTP_DOMAIN"],
41
+ enable_starttls_auto: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
42
+ tls: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? true : false,
43
+ # password: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PASSWORD'] : ENV["MAILER_SMTP_PASSWORD"],
44
+ port: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_PORT'] : ENV["MAILER_SMTP_PORT"],
45
+ # user_name: ENV["USE_MANDRILL_MAILER"].to_i == 1 ? ENV['MANDRILL_SMTP_USERNAME'] : ENV["MAILER_SMTP_USERNAME"],
46
+ # openssl_verify_mode: "none",
47
+ }
48
+
49
+ if ENV["USE_MANDRILL_MAILER"].to_i == 1
50
+ smtp_settings[: authentication] = 'plain'
51
+ smtp_settings[: password] = ENV['MANDRILL_SMTP_PASSWORD']
52
+ smtp_settings[: user_name] = ENV['MANDRILL_SMTP_USERNAME']
53
+ end
54
+
55
+ ActionMailer::Base.smtp_settings = smtp_settings
56
+
57
+ ActionMailer::Base.default_url_options = {
58
+ : host => ENV["BASE_URL_FE"]
59
+ }
60
+ ActionMailer::Base.register_preview_interceptor(ActionMailer::InlinePreviewInterceptor)
61
+
62
+ # Don 't care if the mailer can't send.
63
+ ActionMailer::Base.raise_delivery_errors = true
64
+ ActionMailer::Base.perform_deliveries = true
65
+ ActionMailer::Base.perform_caching = false
66
+
67
+ MandrillMailer.configure do |config |
68
+ config.api_key = ENV["MANDRILL_SMTP_PASSWORD"]
69
+ config.deliver_later_queue_name =: default
66
70
  end
67
71
  ```
68
72
 
@@ -73,65 +77,72 @@ end
73
77
 
74
78
 
75
79
  ```ruby
76
- class MandrillMailer
77
- class << self
78
- def send_email(customer: nil, email_template: nil, attachments: nil, description: nil)
79
- raise "invalid customer" if customer.nil?
80
- raise "invalid template" if email_template.nil?
81
- begin
82
- response = ::DcidevMailer::Mandrill.send_email(
83
- subject: email_template.subject,
84
- html_body: MailerHelper.format_wording(email_template.wording, customer),
85
- header_url: email_template.header.try(:url),
86
- footer_url: email_template.footer.try(:url),
87
- to: customer.email,
88
- cc: nil,
89
- bcc: nil,
90
- from: ENV['DEFAULT_EMAIL_SENDER'],
91
- attachments: attachments,
92
- email_template_path: "mail/blast.html.erb" # specify template file location
93
- )
94
- rescue => e
95
- error_message = "[SEND EMAIL] " + e.try(:to_s)
96
- ensure
97
- EmailHistory.create(application: customer.application, template: email_template, status: response[0]["status"] == "sent" ? :sent : :failed, mail_provider_id: response[0]["_id"], form_cetak_attachment: attachments.present?, error_message: response[0]["reject_reason"]) if response.present?
98
- ApplicationHistory.log(description: error_message || description, application: customer.application)
99
- end
100
- end endend
80
+ require 'dcidev_mailer/mandrill'
81
+
82
+ class MandrillMailer
83
+ class << self
84
+ def send_email(customer: nil, email_template: nil, attachments: nil, description: nil)
85
+ raise "invalid customer"if customer.nil?
86
+ raise "invalid template" if email_template.nil ?
87
+ begin
88
+ response = ::DcidevMailer::Mandrill.send_email(
89
+ subject: email_template.subject,
90
+ html_body: MailerHelper.format_wording(email_template.wording, customer),
91
+ header_url: email_template.header.try(: url),
92
+ footer_url: email_template.footer.try(: url),
93
+ to: customer.email,
94
+ cc: nil,
95
+ bcc: nil,
96
+ from: ENV['DEFAULT_EMAIL_SENDER'],
97
+ attachments: attachments,
98
+ email_template_path: "mail/blast.html.erb"
99
+ # specify template file location
100
+ )
101
+ rescue => e
102
+ error_message = "[SEND EMAIL] " + e.try(: to_s)
103
+ ensure
104
+ EmailHistory.create(application: customer.application, template: email_template, status: response[0]["status"] == "sent" ? : sent:: failed, mail_provider_id: response[0]["_id"], form_cetak_attachment: attachments.present ? , error_message : response[0]["reject_reason"]) if response.present ?
105
+ ApplicationHistory.log(description: error_message || description, application: customer.application)
106
+ end
107
+ end
108
+ end
101
109
  ```
102
110
 
103
111
  ### Action Mailer Example
104
112
  ```ruby
113
+ require 'dcidev_mailer/rails_mailer'
114
+
105
115
  class MortgageMailer
106
- class << self
107
- def email(customer: nil, template: nil, file_attachments: nil, description: nil)
108
- begin
109
- raise "invalid customer" if customer.nil?
110
- raise "invalid template" if template.nil?
111
- raise "email is empty" if customer.email.nil?
112
-
113
- wording, _ = DcidevMailer.format_image_from_html(template.wording)
114
- wording = MailerHelper.format_wording(wording,customer)
115
-
116
- DcidevMailer::RailsMailer.email(
117
- html_body: wording,
118
- header_url: template.header.try(:url),
119
- footer_url: template.footer.try(:url),
120
- file_attachments: file_attachments,
121
- to: customer.email,
122
- cc: nil,
123
- bcc: nil,
124
- subject: template.subject,
125
- from: ENV['DEFAULT_EMAIL_SENDER'],
126
- template_path: "mail/blast.html.erb" # specify template file location
127
- )
128
- rescue => e
129
- error_message = "[SEND EMAIL] " + e.try(:to_s)
130
- ensure
131
- EmailHistory.create(status: error_message.present? ? :failed : :sent, error_message: error_message, application: customer.application, template: template, form_cetak_attachment: file_attachments.present?)
132
- ApplicationHistory.log(description: error_message || description, application: customer.application)
133
- end
134
- end end
116
+ class << self
117
+ def email(customer: nil, template: nil, file_attachments: nil, description: nil)
118
+ begin
119
+ raise "invalid customer" if customer.nil?
120
+ raise "invalid template" if template.nil?
121
+ raise "email is empty" if customer.email.nil?
122
+
123
+ wording, _ = DcidevMailer.format_image_from_html(template.wording)
124
+ wording = MailerHelper.format_wording(wording,customer)
125
+
126
+ DcidevMailer::RailsMailer.email(
127
+ html_body: wording,
128
+ header_url: template.header.try(:url),
129
+ footer_url: template.footer.try(:url),
130
+ file_attachments: file_attachments,
131
+ to: customer.email,
132
+ cc: nil,
133
+ bcc: nil,
134
+ subject: template.subject,
135
+ from: ENV['DEFAULT_EMAIL_SENDER'],
136
+ template_path: "mail/blast.html.erb" # specify template file location
137
+ )
138
+ rescue => e
139
+ error_message = "[SEND EMAIL] " + e.try(:to_s)
140
+ ensure
141
+ EmailHistory.create(status: error_message.present? ? :failed : :sent, error_message: error_message, application: customer.application, template: template, form_cetak_attachment: file_attachments.present?)
142
+ ApplicationHistory.log(description: error_message || description, application: customer.application)
143
+ end
144
+ end
145
+ end
135
146
  end
136
147
  ```
137
148
 
@@ -1,25 +1,27 @@
1
- require "mandrill"
1
+ require 'mandrill'
2
2
 
3
3
  module DcidevMailer
4
4
  class Mandrill < MandrillMailer::MessageMailer
5
5
  default from: ENV['DEFAULT_EMAIL_SENDER']
6
6
 
7
7
  class << self
8
- def send_email(subject: "", html_body: "", to: nil, from: nil, attachments: nil, email_template_path: "", header_url: "", footer_url: "")
8
+ def send_email(subject: '', html_body: '', to: nil, cc: nil, bcc: nil, from: nil, attachments: nil, email_template_path: '', header_url: '', footer_url: '')
9
9
  ac = ActionController::Base.new
10
10
  wording, images = DcidevMailer.format_image_from_html(html_body)
11
- locals = {wording: wording, header: nil, footer: nil}
11
+ locals = { wording: wording, header: nil, footer: nil }
12
12
  locals, images = DcidevMailer.format_header_footer(header_url: header_url, footer_url: footer_url, locals: locals, images: images) if header_url.present? && footer_url.present?
13
13
  html_body = ac.render_to_string(template: email_template_path, locals: locals)
14
14
  attachments = DcidevMailer.format_attachments(attachments) if attachments.present?
15
- self.send_mail(subject, to, html_body, attachments, images, from).deliver_now
15
+ self.send_mail(subject, to, cc, bcc, html_body, attachments, images, from).deliver_now
16
16
  end
17
17
 
18
- def send_mail(subject, to, html, attachments = nil, images = nil, from = nil)
18
+ def send_mail(subject, to, cc, bcc, html, attachments = nil, images = nil, from = nil)
19
19
  mandrill_mail subject: subject,
20
- from: from,
20
+ from: from,
21
21
  # to: "dev.puntodamar@gmail.com",
22
22
  to: to,
23
+ cc: cc,
24
+ bcc: bcc,
23
25
  # to: { email: invitation.email, name: 'Honored Guest' },
24
26
  html: html,
25
27
  view_content_link: true,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dcidev_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Punto Damar P