0

I am trying to embed an image to html when sending email.

I have the image (logo.png) and html (welcome.html.eex) located under priv

Sadly, I receive the email without the image in it.

here is the email I receive:

email received

when I inspect element I get: (no src=" ... ")

<img width="212px" height="26px" align="bottom">

though - when I preview locally my html (from my-html.html - see in my code ) seems ok:

local html

here is my welcome.html.eex

<p>
   <span>
   <strong>Bem-Vindo hii</strong> à 
   <img
      src="<%=  ~s(data:image/png;base64,) <> Base.encode64(File.read! (Path.join("#{:code.priv_dir(:my_app)}", "logo.png"))) %>" 
      width="212px" height="26px" align="bottom"/>
   </span>
</p>

here is my code, sending email adding the html using bamboo:

  import Bamboo.Email

  def send_verify_email() do
      File.write "my-html.html", get_html() # writing the html localy - to verify..
      new_email()
          |> to("foo@bar.com")
          |> from(@from_addr)
          |> subject("Welcome")
          |> html_body(get_html())
          |> Mailer.deliver_later
    end
  end

  def get_html() do
      EEx.eval_file(Path.join("#{:code.priv_dir(:my_app)}", "welcome.html.eex"), [tok: "123"])

  end

what am I doing wrong? how can I attach a base 64 image on email html?

edit

I also tried adding image by path

welcome.html.eex

 <img src="<%= Path.join("#{:code.priv_dir(:my_app)}", "logo.png") %>"

but still get same results - locally html seems ok, but on email html is:

email by bath

when I inspect I get

<img src="https://ci4.googleusercontent.com/proxy/4eMU8Te6MM215JLJ5gm3Z9jnC4hytOkDeF4ldFGb1pC17GDhtZphCtH623p1ZwNYZxBfAatQtlX_V9MKALbOE0jIzxVXJ43tZLeA5hUT7tjs7FEz3_PVoUQ5Ih7w0rvuRtLy7pVqR9UoU5TBF5E=s0-d-e1-ft#http:///home/dina/Documents/WK/my_umbrela_app/_build/dev/lib/my_app/priv/logo.png" width="212px" height="26px" align="bottom" class="CToWUd">

so I do have src="" but it seems broken.. :(

dina
  • 4,039
  • 6
  • 39
  • 67
  • 1
    According to a comment on https://stackoverflow.com/questions/9110091/base64-encoded-images-in-email-signatures, this kind of embedding is not supported by Gmail and possibly other clients as well. Check out the second answer to that question which has a solution which uses attachments to embed images. – Dogbert Oct 03 '17 at 20:25
  • thanks, Ill check the post, please see my edit - tried to add by local path, also didnt work - is that valid ? – dina Oct 03 '17 at 20:48

0 Answers0