Inline Attachment

This package adds full support for embedding inline images into your HTML emails through ActionMailer.

It is created from a Rails patch #2179 (found at dev.rubyonrails.org/ticket/2179).

The goal of this gem is to remove the need for manual patching.

Installation

To perform a system wide installation:

gem install inline_attachment

To use inline_attachment in your project, add the following line to your project’s config/environment.rb:

require 'inline_attachment'

Usage

Embed Images Manually

The code to add inline attachments into your HTML emails is pretty simple:

@cid = Time.now.to_f.to_s + “[email protected]

inline_attachment :content_type => “image/png”, :body => File.read(“#RAILS_ROOT/public/images/foobar.png”), :filename => “foobar.png”, :cid => “<#@cid>” Note that the above code should go into your ActionMailer.

The instance variable @cid is the unique identifier your MIME email will be using to locate the attached image. All you have to do is then pass it over to your email template, and display it like so:

<img src=“cid:<%= @cid %>” alt=“Foo Bar” />

Embed Images Automatically

As of version 0.2.0, Inline Attachment automatically embeds any images found within your ActionMailer templates. There is no longer any extra code required when adding images into your mail templates. Though, you must use rails image_tag helper when displaying images within your mailer views.