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

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

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

6条回答
  •  佛祖请我去吃肉
    2020-12-02 17:11

    RAILS 5

    In your mail method add your inline attachment pointing to your image:

    class ConfirmationMailer < ActionMailer::Base
      def confirmation_email
          attachments.inline["logo.png"] = File.read("#{Rails.root}/app/assets/images/logo.png")
          mail(to: email, subject: 'test subject')
      end
    end
    

    Then in your mail html view an image_tag with the attachment url:

    <%= image_tag(attachments['logo.png'].url) %>
    

提交回复
热议问题