Sha256: 7d82910389e072be9cb7921579807a7b8c6f4199770de040e4957f6dcc5bcad1

Contents?: true

Size: 1.43 KB

Versions: 78

Compression:

Stored size: 1.43 KB

Contents

module PgEngine
  class BaseMailer < ActionMailer::Base # rubocop:disable Rails/ApplicationMailer
    class MailNotDelivered < StandardError; end

    before_action { @email_object = params[:email_object] }

    default from: lambda { |_mailer|
                    if @email_object.present?
                      email_address_with_name(@email_object.from_address, @email_object.from_name)
                    else
                      email_address_with_name(ENV.fetch('DEFAULT_MAIL_FROM'), ENV.fetch('DEFAULT_MAIL_FROM_NAME'))
                    end
                  },
            reply_to: ->(_mailer) { @email_object.reply_to if @email_object.present? },
            subject: ->(_mailer) { @email_object.subject if @email_object.present? },
            to: ->(_mailer) { @email_object.to if @email_object.present? }

    layout 'pg_layout/mailer'

    # default delivery_method: :smtp

    rescue_from StandardError do |err|
      pg_err err
      # TODO: agregar un backtrace
      @email_object.update_columns(status: :failed, status_detail: err.to_s) if @email_object.present?
    end

    protected

    def mail(*args)
      super.tap do |message|
        # message.mailgun_options = {
        #   'tag' => email.tags,
        #   'tracking-opens' => true
        # }
        message['email_object'] = @email_object if @email_object.present?
      end
    end
  end
end

#   # TODO: testear
#       si from está vacío
#       si body está vacío

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
pg_rails-7.4.3 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.4.2 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.4.1 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.4.0 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.3.5 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.3.4 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.3.3 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.3.2 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.3.1 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.3.0 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.2.3 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.2.2 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.2.1 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.2.0 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.1.16 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.1.15 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.1.14 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.1.13 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.1.12 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.1.11 pg_engine/app/mailers/pg_engine/base_mailer.rb