Add an image from a URL as an attachment in Rails 3

I know that you can add an image as an attachment to an email in Rails 3 with

def email_image(email)
  attachments["img"] = File.read('/path to image')
  mail(:to => email)
end

but is there a way to bind an image to a url, not a local one? I would like to add an image that is saved on S3 using a paper clip. Is there an easy way to do this or do I need to upload an image first?

+3
source share
2 answers

you need

require 'open-uri'

and then do

attachments["filename"] = open(url-to-image).read
+7
source

If you use html, you can just insert the image tag. The only problem is that most email clients will block the image until the user "trusts" you.

, , . , .

0

All Articles