Sha256: f02bec8f5fc0a00d8404924f8e1402a3f3acaa0ffbf315c0809355d17832f0f8

Contents?: true

Size: 894 Bytes

Versions: 9

Compression:

Stored size: 894 Bytes

Contents

require 'action_mailer/railtie'

module MnoEnterprise
  # Base class (instantiable) for SMTP adapter
  class SmtpClient < ActionMailer::Base
    # 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

9 entries across 9 versions & 1 rubygems

Version Path
mno-enterprise-core-3.2.1 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.3.1 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.3.0 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.2.0 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.1.4 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.1.3 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.1.2 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.1.1 lib/mno_enterprise/smtp_client.rb
mno-enterprise-core-3.1.0 lib/mno_enterprise/smtp_client.rb