Sha256: f7752ea4a120b09f58e3c23a2cb6c4f1bff0e63874b503740ddc982489b3ebd9

Contents?: true

Size: 1.29 KB

Versions: 21

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

# frozen_string_literal: true

module NeetoCommonsBackend
  module Initializers
    class << self
      def neeto_email_prefixer
        NeetoEmailPrefixer.configure do |config|
          config.application_name = ((Rails.application.secrets.mailer || {})[:default_from_name]) || ""
          config.stage_name = Rails.env
        end

        ActiveSupport.on_load(:action_mailer) do
          ActionMailer::Base.class_eval do
            default custom_prefix_override: -> { organization_name }

            private
            def organization_name
              if params.nil? || params[:organization_name].nil?
                raise ArgumentError, <<~MSG
                  Missing organization_name parameter in mailer. Please add it to the mailer params.

                  Suppose the name of the mailer is UserMailer, and you are trying to send a mail via
                  UserMailer, you need to add the following parameter like so:

                  UserMailer.with(organization_name: organization_name).send_email.deliver

                  Please pass the appropriate organization name to the mailer.
                MSG
              else
                params[:organization_name]
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
neeto-commons-backend-1.0.109 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.108 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.107 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.106 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.105 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.104 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.103 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.102 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.101 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.100 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.99 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.98 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.97 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.96 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.95 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.94 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.93 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.92 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.91 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb
neeto-commons-backend-1.0.90 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb