I have a paperclip'd file that I want to add as an attachment to my email....
class UserMailer < ActionMailer::Base def XXXXXX_notification(record) @record = record
attachments ??? How to add a paperclip file?
mail( :to => "#{record.email}",
:subject => "XXXXXXXX"
)
end
There seems to be nothing on the topic via google, if you have any ideas, I'd love to hear it :)
Thanks
UPDATE
@comment.attachments.each do |a|
tempfile = File.new("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}", "w")
tempfile << open(a.authenticated_url())
tempfile.puts
attachments[a.attachment_file_name] = File.read("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}")
# Delete it tempfile
#File.delete("#{Rails.root.to_s}/tmp/#{a.filename}")
end
It has been already answered but I just want to share a slightly different way to do it:
Here is my model Report. I'm using Paperclip.
class Report < ActiveRecord::Base
has_attached_file :pdf_file
...
end
And here is my mailer ReportMailer
class ReportMailer < ActionMailer::Base
def monthly_report_email(emails, report)
attachments[report.pdf_file_file_name] = File.read(report.pdf_file.path)
mail(:to => emails, :subject => 'monthly report')
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With