2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-07-23 08:42:21 -04:00
|
|
|
class BaseMailer < ActionMailer::Base
|
|
|
|
self.mailer_name = "base_mailer"
|
|
|
|
|
2016-08-06 13:03:39 -04:00
|
|
|
default to: "system@test.lindsaar.net",
|
|
|
|
from: "jose@test.plataformatec.com",
|
2019-06-10 09:47:46 -04:00
|
|
|
reply_to: email_address_with_name("mikel@test.lindsaar.net", "Mikel")
|
2010-07-23 08:42:21 -04:00
|
|
|
|
|
|
|
def welcome(hash = {})
|
2016-08-06 13:03:39 -04:00
|
|
|
headers["X-SPAM"] = "Not SPAM"
|
2016-08-16 03:30:11 -04:00
|
|
|
mail({ subject: "The first email on new API!" }.merge!(hash))
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def welcome_with_headers(hash = {})
|
|
|
|
headers hash
|
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
|
|
|
def welcome_from_another_path(path)
|
2012-10-07 13:54:14 -04:00
|
|
|
mail(template_name: "welcome", template_path: path)
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
|
2019-02-13 09:55:38 -05:00
|
|
|
def welcome_without_deliveries(hash = {})
|
|
|
|
mail({ template_name: "welcome" }.merge!(hash))
|
2018-09-08 04:14:12 -04:00
|
|
|
mail.perform_deliveries = false
|
|
|
|
end
|
|
|
|
|
2019-06-10 09:47:46 -04:00
|
|
|
def with_name
|
|
|
|
to = email_address_with_name("sunny@example.com", "Sunny")
|
|
|
|
mail(template_name: "welcome", to: to)
|
|
|
|
end
|
|
|
|
|
2010-07-23 08:42:21 -04:00
|
|
|
def html_only(hash = {})
|
|
|
|
mail(hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def plain_text_only(hash = {})
|
|
|
|
mail(hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def inline_attachment
|
2016-08-06 13:03:39 -04:00
|
|
|
attachments.inline["logo.png"] = "\312\213\254\232"
|
2010-07-23 08:42:21 -04:00
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
2016-09-10 05:53:37 -04:00
|
|
|
def inline_and_other_attachments
|
|
|
|
attachments.inline["logo.png"] = "\312\213\254\232"
|
|
|
|
attachments["certificate.pdf"] = "This is test File content"
|
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
2010-07-23 08:42:21 -04:00
|
|
|
def attachment_with_content(hash = {})
|
2016-08-06 13:03:39 -04:00
|
|
|
attachments["invoice.pdf"] = "This is test File content"
|
2010-07-23 08:42:21 -04:00
|
|
|
mail(hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachment_with_hash
|
2016-08-06 13:03:39 -04:00
|
|
|
attachments["invoice.jpg"] = { data: ::Base64.encode64("\312\213\254\232)b"),
|
2012-10-07 13:54:14 -04:00
|
|
|
mime_type: "image/x-jpg",
|
|
|
|
transfer_encoding: "base64" }
|
2010-07-23 08:42:21 -04:00
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachment_with_hash_default_encoding
|
2016-08-06 13:03:39 -04:00
|
|
|
attachments["invoice.jpg"] = { data: "\312\213\254\232)b",
|
2012-10-07 13:54:14 -04:00
|
|
|
mime_type: "image/x-jpg" }
|
2010-07-23 08:42:21 -04:00
|
|
|
mail
|
|
|
|
end
|
|
|
|
|
|
|
|
def implicit_multipart(hash = {})
|
2016-08-06 13:03:39 -04:00
|
|
|
attachments["invoice.pdf"] = "This is test File content" if hash.delete(:attachments)
|
2010-07-23 08:42:21 -04:00
|
|
|
mail(hash)
|
|
|
|
end
|
|
|
|
|
2019-03-01 17:07:59 -05:00
|
|
|
def implicit_multipart_formats(hash = {})
|
|
|
|
mail(hash)
|
|
|
|
end
|
|
|
|
|
2010-07-23 08:42:21 -04:00
|
|
|
def implicit_with_locale(hash = {})
|
|
|
|
mail(hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
def explicit_multipart(hash = {})
|
2016-08-06 13:03:39 -04:00
|
|
|
attachments["invoice.pdf"] = "This is test File content" if hash.delete(:attachments)
|
2010-07-23 08:42:21 -04:00
|
|
|
mail(hash) do |format|
|
2016-05-21 08:49:38 -04:00
|
|
|
format.text { render plain: "TEXT Explicit Multipart" }
|
|
|
|
format.html { render plain: "HTML Explicit Multipart" }
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def explicit_multipart_templates(hash = {})
|
|
|
|
mail(hash) do |format|
|
|
|
|
format.html
|
|
|
|
format.text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def explicit_multipart_with_any(hash = {})
|
|
|
|
mail(hash) do |format|
|
2016-05-21 08:49:38 -04:00
|
|
|
format.any(:text, :html) { render plain: "Format with any!" }
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-18 13:26:42 -04:00
|
|
|
def explicit_without_specifying_format_with_any(hash = {})
|
|
|
|
mail(hash) do |format|
|
|
|
|
format.any
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-07-23 08:42:21 -04:00
|
|
|
def explicit_multipart_with_options(include_html = false)
|
|
|
|
mail do |format|
|
2016-08-16 03:30:11 -04:00
|
|
|
format.text(content_transfer_encoding: "base64") { render "welcome" }
|
|
|
|
format.html { render "welcome" } if include_html
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def explicit_multipart_with_one_template(hash = {})
|
|
|
|
mail(hash) do |format|
|
|
|
|
format.html
|
|
|
|
format.text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
def implicit_different_template(template_name = "")
|
2012-10-07 13:54:14 -04:00
|
|
|
mail(template_name: template_name)
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
|
2018-11-19 19:23:44 -05:00
|
|
|
def implicit_different_template_with_block(template_name = "")
|
2015-12-08 06:28:00 -05:00
|
|
|
mail(template_name: template_name) do |format|
|
|
|
|
format.text
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
def explicit_different_template(template_name = "")
|
2010-07-23 08:42:21 -04:00
|
|
|
mail do |format|
|
2012-10-07 13:54:14 -04:00
|
|
|
format.text { render template: "#{mailer_name}/#{template_name}" }
|
|
|
|
format.html { render template: "#{mailer_name}/#{template_name}" }
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
def different_layout(layout_name = "")
|
2010-07-23 08:42:21 -04:00
|
|
|
mail do |format|
|
2012-10-07 13:54:14 -04:00
|
|
|
format.text { render layout: layout_name }
|
|
|
|
format.html { render layout: layout_name }
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|
|
|
|
end
|
2010-08-26 14:19:55 -04:00
|
|
|
|
|
|
|
def email_with_translations
|
2012-10-07 13:54:14 -04:00
|
|
|
mail body: render("email_with_translations", formats: [:html])
|
2010-08-26 14:19:55 -04:00
|
|
|
end
|
2012-09-29 16:29:29 -04:00
|
|
|
|
|
|
|
def without_mail_call
|
|
|
|
end
|
2012-12-07 08:43:49 -05:00
|
|
|
|
2013-03-19 01:23:32 -04:00
|
|
|
def with_nil_as_return_value
|
2013-11-14 03:11:37 -05:00
|
|
|
mail(template_name: "welcome")
|
2012-12-07 08:43:49 -05:00
|
|
|
nil
|
|
|
|
end
|
2013-01-23 13:22:39 -05:00
|
|
|
|
|
|
|
def with_subject_interpolations
|
2016-08-06 13:03:39 -04:00
|
|
|
mail(subject: default_i18n_subject(rapper_or_impersonator: "Slim Shady"), body: "")
|
2013-01-23 13:22:39 -05:00
|
|
|
end
|
2010-07-23 08:42:21 -04:00
|
|
|
end
|