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.89 lib/neeto_commons_backend/initializers/neeto_email_prefixer.rb