Forum: Ruby Send Mail with inline images?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9a1b1136b42f179b246b9d3eb66fc996?d=identicon&s=25 Christoph B. (christoph_b)
on 2011-02-25 01:27
Hey,

I've got the following problem:
I have got a complete html page with inline CSS and images (with remote
urls) that I want to send as a html email.

So what I need to do is:

1. loop through img tags, extract url
2. attach image, fetch cid
3. change img src to cid:<contentid>

Can anyone tell me what to use for this? I need something that
returns the content id after I attach an image, so I can change it in
the html.

Thanks in advance,
Christoph
06f88a19dfc26c913f84d6b8d9edf0a6?d=identicon&s=25 soldier.coder (Guest)
on 2011-02-25 07:51
(Received via mailing list)
On Feb 24, 7:28pm, "Christoph B." <ch.bl...@gmail.com> wrote:
> 3. change img src to cid:<contentid>
>
> Can anyone tell me what to use for this? I need something that
> returns the content id after I attach an image, so I can change it in
> the html.
>
> Thanks in advance,
> Christoph
>
> --
> Posted viahttp://www.ruby-forum.com/.

Whats a cid??
7b56484f1e9d9af7b4c2c7ef16142197?d=identicon&s=25 Martin Boese (Guest)
on 2011-02-25 14:23
(Received via mailing list)
On Fri, 25 Feb 2011 09:28:01 +0900
"Christoph B." <ch.blank@gmail.com> wrote:

> 3. change img src to cid:<contentid>
>
> Can anyone tell me what to use for this? I need something that
> returns the content id after I attach an image, so I can change it in
> the html.

I can't give you a full solution, but to inline the image you can do
this:

  require 'base64'

  fn = '/path/to/image.png'
  src = "data:image/png;base64,#{Base64.encode64(File.read(fn))}"
  new_tag = "<img src='#{src}'>"

Assuming you attach an 'image/png' file.


Martin
This topic is locked and can not be replied to.