Reputation: 700
Here i need to attach one image with mail, the passing image like this
**imageurl** = "https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=%22hai%22&choe=UTF-8"
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def welcome_email(**imageurl**,bname,mailid)
**attachments['image.png'] = File.read(imageURL)**
mail(:to => mailid,
:subject => "Code for "+bname+"",
:body => "code for bname" )
end
end
end
here i got some attachment error. Have any changes in this attachment?
thanks
Upvotes: 0
Views: 441
Reputation: 3137
require 'open-uri'
class UserMailer < ActionMailer::Base
def welcome_email(image_url,bname,mailid)
mail.attachments[image.png] = { :mime_type => type*, :content => open(URI.parse(image_url)}
...
end
end
where type* is the type of attached file in your case it will be('image/png')
Upvotes: 0
Reputation: 13433
i think you have a URL i.e a string which File.read cannot read.
require 'open-uri'
class UserMailer < ActionMailer::Base
def welcome_email(image_url,bname,mailid)
attachments['image.png'] = open(URI.parse(image_url))
...
end
end
The above should do the trick i think.
Upvotes: 2