Within my Ruby on Rails application I am trying to embed a logo in an email to be displayed inline, but for some reason it does not appear (please see the below image). I have tried to follow the answers on this Stack Overflow question What is the right way to embed image into email using Rails? but cannot get it to work.
My mailer is as follows:
class UserEmails < ApplicationMailer
def send_email(email, unsubscribe)
@url = 'http://localhost:3000/users/login'
@email = email
@unsubscribe = unsubscribe
attachments.inline['logo.jpg'] = File.read('app/assets/images/logo.jpg')
mail(from: "#{@email.from_name} <#{@email.account.email}>", to: @email.to, cc: @email.cc, bcc: @email.bcc, subject: @email.subject)
end
end
And my email view:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1><%= @email.subject %></h1>
<p>
<p>
To
<%= image_tag attachments['logo.jpg'].url %>
<%= link_to "Unsubscribe", settings_unsubscribe_url(id: @unsubscribe) %>
</body>
</html>
Is anyone able to tell me why this isn't working?