Class: CamaleonCms::HtmlMailer

Inherits:
ActionMailer::Base
  • Object
show all
Includes:
HooksHelper, PluginsHelper, SiteHelper
Defined in:
app/mailers/camaleon_cms/html_mailer.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Methods included from PluginsHelper

#current_plugin, #plugin_asset_path, #plugin_asset_url, #plugin_destroy, #plugin_install, #plugin_layout, #plugin_load_helpers, #plugin_uninstall, #plugin_upgrade, #plugin_view, #plugins_initialize, #self_plugin_key

Methods included from HooksHelper

#hook_run, #hook_skip, #hooks_run

Methods included from SiteHelper

#cama_get_list_layouts_files, #cama_get_list_template_files, #cama_site_check_existence, #current_locale, #current_site, #current_theme, #site_after_install, #site_console_switch, #site_install_theme, #site_load_custom_models, #site_uninstall_theme

Instance Method Details

#sender(email, subject = 'Hello', content = '', from = nil, attachs = [], url_base = '', current_site, template_name, layout_name, extra_data) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/mailers/camaleon_cms/html_mailer.rb', line 17

def sender(email, subject='Hello', content='', from=nil, attachs=[], url_base='', current_site, template_name, layout_name, extra_data)
  @subject = subject
  @html = content
  @url_base = url_base
  @current_site = current_site
  @extra_data = extra_data

  mail_data = {to: email, subject: subject}
  mail_data[:from] = from if from.present?

  if current_site.get_option("mailer_enabled") == 1
    mail_data[:from] = current_site.get_option("email_from")
    mail_data[:cc] = current_site.get_option("email_cc")
    mail_data[:delivery_method] = :smtp
    mail_data[:delivery_method_options] = {user_name: current_site.get_option("email_username"),
                                           password: current_site.get_option("email_pass"),
                                           address: current_site.get_option("email_server"),
                                           port: current_site.get_option("email_port"),
                                           domain: (current_site.the_url.to_s.parse_domain rescue "localhost"),
                                           authentication: "plain",
                                           enable_starttls_auto: true
    }
  end

  views_dir = "app/apps/"
  self.prepend_view_path(File.join($camaleon_engine_dir, views_dir).to_s)
  self.prepend_view_path(Rails.root.join(views_dir).to_s)

  theme = current_site.get_theme
  lookup_context.prefixes.prepend("themes/#{theme.slug}") if theme.settings["gem_mode"]
  lookup_context.prefixes.prepend("themes/#{theme.slug}/views") unless theme.settings["gem_mode"]

  # run hook "email" to customize values
  r = {template_name: template_name, layout_name: layout_name, mail_data: mail_data, files: attachs, format: "html"}
  hooks_run("email", r)

  if r[:files].present?
    r[:files].each { |attach| attachments["#{File.basename(attach)}"] = File.open(attach, 'rb') { |f| f.read } }
  end

  mail(r[:mail_data]) { |format| format.html { render r[:template_name], layout: r[:layout_name] } } if r[:format] == "html"
  mail(r[:mail_data]) { |format| format.text { render r[:template_name], layout: r[:layout_name] } } if r[:format] == "txt"
  mail(r[:mail_data]) unless r[:format].present?

end