lib/eco/api/common/session/mailer.rb in eco-helpers-2.1.3 vs lib/eco/api/common/session/mailer.rb in eco-helpers-2.1.4

- old
+ new

@@ -14,15 +14,13 @@ # Sends an email # @param to [String] destination email address # @param subject [String] subject of the email # @param body [String] `html` or plain text message - def mail(to: nil, subject:, body:) + def mail(to: nil, subject:, body:, cc: nil, bcc: nil) ses.send_email( - destination: { - to_addresses: [fetch_to(to)].flatten, - }, + destination: fetch_destination(to: to, cc: cc, bcc: bcc), source: fetch_from, message: { subject: { charset: "UTF-8", data: subject, @@ -60,9 +58,18 @@ @enviro&.logger || ::Logger.new(IO::NULL) end def config @enviro.config || {} + end + + def fetch_destination(to: nil, cc: nil, bcc: nil) + cc_to = [cc].flatten.compact.uniq + bcc_to = [bcc].flatten.compact.uniq + { to_addresses: [fetch_to(to)].flatten }.tap do |dest| + dest.merge!(cc_addresses: cc_to) unless cc_to.empty? + dest.merge!(bcc_addresses: bcc_to) unless bcc_to.empty? + end end def fetch_to(value = nil) value || config.mailer.to end