Ask A Question

Notifications

You’re not receiving notifications from this thread.

Ruby on Rails ActionMailer Images Issue

Maximilian Kirsch asked in General

I'm trying to use embedded images in my E-Mail, but if I try to load a file from my image folder as a header, it's not displaying in the email:

The image is an inline attachment:

def export_bill_email(user)
        @user = user
        attachments.inline["logo.jpg"] = File.read("#{Rails.root}/app/assets/images/bdh_caption_logo.jpg")
        make_bootstrap_mail(
            to: 'xxx',
            from: 'xxx',
            subject: 'xxx'
        )
    end

(Don't mind the make_bootstrap_mailmethod here, I'm using the bootstrap email gem - I also tried it with the standard mail method - doesn't work either :/.

Then in my view, I try to call it the following way:

<%= image_tag(attachments["logo.jpg"].url, width: '100', height: '100') %>

Is it not displaying cause of development mode? I also tried forwarding with ngrok, but still, it's just displaying a broken image sign in my received email.
The strange thing is: If I use a direct hyperlink to an image, it is displayed so it has to do something with the image URL I guess, but I can't figure it out.

I could use the asset host method in my environment file, but this way I had to host the images like forever so they get displayed correctly in the mails, so I would rather like to go with an attachment.

Thanks for any good advice!

Reply

Hey Maximilian!

I haven't actually done this before, but it looks like you're mostly on the right path. I found this on Stack Overflow that looks very similar. https://stackoverflow.com/a/25810153

Does the email have the image as an attachment and it's just not showing inline?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.