Inline attachments appear as downloadables

81 views
Skip to first unread message

Thomas Michael

unread,
Jan 16, 2015, 4:27:08 PM1/16/15
to rubyonra...@googlegroups.com
Hello,

I'm attempting to generate emails with inline attachments. I'm using
Action Mailer 4.1.6 and the attachment.inline method, but for some
reason all of my attachments are coming through as regular downloadable
attachments, not as inline attachments. Here's the relevant code:

In emails_mailer.rb:

def send_email(email)
attachments.inline['receipt.jpg'] = {:data =>
File.read("public/items/receipt.jpg").force_encoding("BINARY"),
:mime_type => "image/jpg"}
mail(to: email.recipient, subject: "Email sent on #{Date.today}",
body: email.body)
end

In send_email.html.erb:

<%= image_tag attachments['receipt.jpg'].url %>

I've tried the solutions found here:

http://stackoverflow.com/questions/8356924/rails-attachments-inline-are-not-shown-correctly-in-gmail
http://stackoverflow.com/questions/16564366/rails-inline-mail-attachments-not-working-properly?lq=1
http://www.rubydoc.info/docs/rails/4.1.7/ActionMailer/Base

Still, the email always comes through as a downloadable image. I'm
using Rails 4.1.6.

Any advice or pointers in the right direction?

--
Posted via http://www.ruby-forum.com/.

Scott Ribe

unread,
Jan 16, 2015, 4:33:27 PM1/16/15
to rubyonra...@googlegroups.com, Thomas Michael
On Jan 16, 2015, at 2:25 PM, Thomas Michael <li...@ruby-forum.com> wrote:
>
> Still, the email always comes through as a downloadable image. I'm
> using Rails 4.1.6.
>
> Any advice or pointers in the right direction?

I notice that you're not setting the encoding to base64 as suggested in the first link you posted.

Also, have you examined the actual email raw source as delivered? Even after get the image properly encoded inline, it's up to the email client whether or not it decides to actually display it inline.

--
Scott Ribe
scott...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




Sillius Soddus

unread,
Jan 16, 2015, 4:47:24 PM1/16/15
to rubyonra...@googlegroups.com
Scott Ribe wrote in post #1166818:
> On Jan 16, 2015, at 2:25 PM, Thomas Michael <li...@ruby-forum.com>
> wrote:
>>
>> Still, the email always comes through as a downloadable image. I'm
>> using Rails 4.1.6.
>>
>> Any advice or pointers in the right direction?
>
> I notice that you're not setting the encoding to base64 as suggested in
> the first link you posted.
>
> Also, have you examined the actual email raw source as delivered? Even
> after get the image properly encoded inline, it's up to the email client
> whether or not it decides to actually display it inline.

Good advice. I removed the base64 encoding because the image wasn't
showing up at all.

I actually discovered the problem shortly after posting this: in
send_email, I am setting body: email.body. So the view will never
render.
Reply all
Reply to author
Forward
0 new messages