you have mention about how to store files in database. How to attach those files with mail using action mailer? I have search many sites but not able to find the way to attach database files. Everywhere the help of attaching files stored in file system is given.
It's not very different from sending attachments stored on disk.
Say you have a model Binary
that corresponds to files in the file system. If it responds to content_type
and data
, then something like this should work:
class AttachmentMailer < ActionMailer::Base
def attachment(recipient, binary)
recipients recipient
subject "Your requested file"
from "example@example.com"
attachment :content_type => binary.content_type, :body => binary.data
end
end
# Wherever you want to e-mail something:
binary = Binary.find(:first)
Notifier.deliver_attachment("user@example.com", binary)
Of course, if you store your data differently or if the database columns are named differently, you should adjust the methods of the Binary
class (or whichever class you use) in the above example.
I hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.