aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-06 06:02:22 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-06 06:03:41 -0500
commite482dce0ed35bed2ab556e95a9f9d1124d65fa15 (patch)
treea648e4d2d810e2d4b362b279d7f7f75d4a7290cb /actionmailer/lib/action_mailer
parentd06d71bb54b17d9a7e1b9d1e7084c2bc1e7a38bc (diff)
parentf091bd67b3ef5f4cd85dbd70cbd11e9ad2711562 (diff)
downloadrails-e482dce0ed35bed2ab556e95a9f9d1124d65fa15.tar.gz
rails-e482dce0ed35bed2ab556e95a9f9d1124d65fa15.tar.bz2
rails-e482dce0ed35bed2ab556e95a9f9d1124d65fa15.zip
Merge pull request #27227 from MQuy/allow-custom-content-type-in-mail-body
Allow to custom content type when setting mailer body
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 19408f2a48..8205743de3 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -208,6 +208,19 @@ module ActionMailer
# end
# end
#
+ # You can also send attachments with html template, in this case you need to add body, attachments,
+ # and custom content type like this:
+ #
+ # class NotifierMailer < ApplicationMailer
+ # def welcome(recipient)
+ # attachments["free_book.pdf"] = File.read("path/to/file.pdf")
+ # mail(to: recipient,
+ # subject: "New account information",
+ # content_type: "text/html",
+ # body: "<html><body>Hello there</body></html>")
+ # end
+ # end
+ #
# = Inline Attachments
#
# You can also specify that a file should be displayed inline with other HTML. This is useful
@@ -896,15 +909,19 @@ module ActionMailer
yield(collector)
collector.responses
elsif headers[:body]
- [{
- body: headers.delete(:body),
- content_type: self.class.default[:content_type] || "text/plain"
- }]
+ collect_responses_from_text(headers)
else
collect_responses_from_templates(headers)
end
end
+ def collect_responses_from_text(headers)
+ [{
+ body: headers.delete(:body),
+ content_type: headers[:content_type] || "text/plain"
+ }]
+ end
+
def collect_responses_from_templates(headers)
templates_path = headers[:template_path] || self.class.mailer_name
templates_name = headers[:template_name] || action_name