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.6.21.pre.11 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.10 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.9 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.8 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.7 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.6 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.5 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.4 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.3 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.2 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.21.pre.1 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.20 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.19 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.18 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.17 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.16 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.15 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.14 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.13 pg_engine/app/mailers/pg_engine/base_mailer.rb
pg_rails-7.6.12 pg_engine/app/mailers/pg_engine/base_mailer.rb