What is the right way to embed image into email using Rails?

后端 未结 6 1604
后悔当初
后悔当初 2020-12-02 16:23

What is the right way to embed an image into email using Rails?

6条回答
  •  無奈伤痛
    2020-12-02 17:02

    Adding onto Oksana and tdubs' answers

    The module tdubs wrote works on desktop, but for the mobile gmail client, the images appeared as attachments. To fix this, do this for the

    app/helpers/email_helper.rb

    module EmailHelper
        def email_image_tag(image, **options)
            attachments[image] = {
                :data => File.read(Rails.root.join("app/assets/images/emails/#{image}")),
                :mime_type => "image/png",
                :encoding => "base64"
            }
            image_tag attachments[image].url, **options
        end
    end
    

    For the rest, follow tdubs's answer.

提交回复
热议问题