Sha256: af699aceb55d834bd8323cfc25e7eedfdae865fa59b791411b1c54acdb2f4ef6

Contents?: true

Size: 937 Bytes

Versions: 3

Compression:

Stored size: 937 Bytes

Contents

require 'action_mailer/railtie'

module MnoEnterprise
  # Base class (instantiable) for SMTP adapter
  class SmtpClient < ActionMailer::Base
    helper MnoEnterprise::ImageHelper
    
    # Send SMTP template - terminal mailing part
    def deliver(template, from, to, vars={}, opts={})
      @info = vars
      @info[:company] = from[:name]

      mail(
        from: format_sender(from),
        to: to[:email],
        subject: humanize(template),
        template_path: 'system_notifications',
        template_name: template
      )
    end 

    # Returns Actionmailer-compliant :from string
    # @Format : "Sender name <sender@email.com>"
    def format_sender(from)
      "#{from[:name]} <#{from[:email]}>"
    end
    
    # Returns humanized template subject
    # @i.e. "reset-password-instructions" to "Reset password instructions"
    def humanize(template_slug)
      template_slug.tr("-", "_").humanize
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mno-enterprise-core-3.4.0 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.3.3 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.3.2 lib/mno_enterprise/smtp_client.rb