bug in Jumpstart > Mailer > shared_settings ; plus how I added support for an ESP I like better

When implementing my own mailer (Socketlabs, who has far better support and pricing plans than my former-favorite Sendgrid) I noticed (a) a poor configuration default, and (b) a small bug related to a misunderstanding of how ruby merge works.

(a) [suggestion] these days smtp authentication ought to default to "login". With enable_starttls_auto set true it's secure either way but some vendors will (wisely) reject "plain" and I'm not aware of any vendors who do no accept (and recommend) "login". So "login" it ought to be the default IMO.

(b) [the bug] the method JSP uses for overriding shared_settings will not work; it works for adding a setting, but not for overriding a setting. As-is the bug only affects mailer methods that try to override a setting (sendinblue_settings) and might not actually break anything. But the code won't do what it acts ike it does.

Ruby's merge does not override an existing setting. Therefore setting `authentication: :login` inside shared_settings, then attempting to override it via merge (as is done in sendinblue_settings() for example) will not change its value.

To see that try this in rails console:

> default_hash = { foo: "FOO-DEFAULT", bar: "BAR-DEFAULT" }
> { something: "HI", foo: "FOO-NEW" }.merge(default_hash)  # wont override :foo
=> {:something=>"HI", :foo=>"FOO-DEFAULT", :bar=>"BAR-DEFAULT"}

So I modified my code to always use :login as shown below, so login will be default. I also added a socketlabs_settings for anyone looking for a low-cost, superior-service ESP.

module Jumpstart
   class Mailer
      ...
     def shared_settings
      {
        port: 587,
        # authentication: :plain, # replace with login, merging wont work to override
        authentication: :login,
        enable_starttls_auto: true
      }
     end
     ...   and for anyone interested in supporting a new ESP, I also added
     def settings
       # added:
       return socketlabs_settings if config.socketlabs?
       .....
     end
      ...
      def socketlabs_settings
      {
        address: "smtp.socketlabs.com",
        authentication: :login,
        user_name: get_credential(:socketlabs, :username),
        password: get_credential(:socketlabs, :password)
      }.merge(shared_settings)
    end
     .... 
  end
end


and in case anyone wants to add a new ESP, in <env>.yml.enc I added a section for socketlabs:

socketlabs:
  username: 'xxxx'
  password: 'yyyyy'

and also added a new blank setting to to credentials_generator.rb :
        socketlabs:
          username: ''
          password: ''

and to mailable.rb I added:

        "Socketlabs" => :socketlabs,

between SendinBlue and SparkPost.

Notifications
You’re not receiving notifications from this thread.
Subscribe
© 2021 GoRails, LLC