lib/eco/api/common/session/mailer.rb in eco-helpers-1.1.2 vs lib/eco/api/common/session/mailer.rb in eco-helpers-1.1.3

- old
+ new

@@ -5,23 +5,24 @@ module API module Common module Session class Mailer + # @param enviro [Eco::API::Common::Session::Environment] def initialize (enviro:) raise "Required Environment object (enviro:). Given: #{enviro}" if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment) @enviro = enviro end # 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:, subject:, body:) + def mail(to: nil, subject:, body:) ses.send_email( destination: { - to_addresses: [to].flatten, + to_addresses: [fetch_to(to)].flatten, }, source: fetch_from, message: { subject: { charset: "UTF-8", @@ -60,9 +61,13 @@ @enviro&.logger || ::Logger.new(IO::NULL) end def config @enviro.config || {} + end + + def fetch_to(value = nil) + value || config.mailer.to end def fetch_from(value = nil) value || config.mailer.from end