FYI,
I was able to solve my problem by changing strategy a little. Instead
of saving the rendered PDF to a file and then using that file in the
attachment I render it in memory and pass that to ActionMailer. This
leads me to believe the problem is with File.read and based on earlier
posts, probably limited to Windows machines.
Sample:
From the controller:
p.render is the pdfwriter method to take my generated PDF and render
it in memory
my_email = MyMailer.create_test_email(@order, p.render)
MyMailer.deliver(my_email)
From MyMailer:
def test_email(order, pdfFile)
@recipients = order.email_address
@from = “UserName [email protected]”
@subject = “Test Email Attachment”
attachment :content_disposition => “attachment”,
:body => pdfFile,
:content_type => “application/pdf”,
:filename => ‘whatever_name_you_want.pdf’
end
Hope this helps someone avoid the same problem that I had with the
incomplete files being read in with File.read.
Regards,
Michael
Michael [email protected] wrote:
Community and/or Ben,
Did you ever get this working on your Windows box? I just posted a
question last night with the same issue. I, too, have a windows box and
am having the same corrupt file problem.
Please advise…
Michael
Ben R. [email protected] wrote:
I finally got the PDF attachments working by changing:
attachment :content_type => “application/pdf”, :body =>
File.read(“pdf/my.pdf”)
to
attachment :content_type => “application/pdf”, :body =>
File.read("#{RAILS_ROOT}/public/pdf/my.pdf"), :filename => “my.pdf”
Now, this method still DOES NOT work for some reason on my Windows
development box. The attachment comes through on the email, but is
corrupted. I was getting no where so I put it on my production box
(Gentoo Linux) and it worked right away. Go figure.
~ Ben
On 5/5/06, Ben R. wrote:
attachment :content_type => “application/pdf”, :body => File.read(“pdf/my.pdf”)
only reference has been the wiki and
http://api.rubyonrails.com/classes/ActionMailer/Base.html
Thx,
–
Ben R.
303-947-0446
http://www.benr75.com
–
Ben R.
303-947-0446
http://www.benr75.com
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail
Beta._______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails