Class: MailEngine::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_engine/base.rb

Constant Summary collapse

@@configurations =
HashWithIndifferentAccess.new

Class Method Summary collapse

Class Method Details

.current_configObject

return current runtime environment config hash.

example

log_mail: true
user_class_name: "User"
mount_at: "/admin"
access_check_method: "logged_in?"
sendgrid:
  sendgrid_user: "[email protected]"
  sendgrid_key: "xxx"
  sendgrid_category: "development"


19
20
21
# File 'lib/mail_engine/base.rb', line 19

def current_config
  MailEngine::Base.configurations[Rails.env] || {}
end

.send_marketing_mail(template, *args) ⇒ Object

send mail template with given data.

example

MailEngine::Base.send_marketing_mail("newsletter", :to => '[email protected]', :values => {:users => MailEngine::USER_MODEL.last})


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mail_engine/base.rb', line 28

def send_marketing_mail(template, *args)
  options = args.extract_options!
  options[:locale] ||= I18n.locale

  # ensure the :to parameter.
  raise "Should specify :to option" if options[:to].blank?

  # find the template from database.
  unless mail_template = MailEngine::MailTemplate.where(:path => template, :locale => options[:locale], :for_marketing => true, :partial => false).first
    raise "Can't find the template: #{template}"
  end

  options[:subject] ||= mail_template.subject
  I18n.with_locale(mail_template.locale) do
    MailEngine::MailDispatcher.send(template, options).deliver
  end
end