Reputation: 517
I am making a Rails app. When user signs up, I send a confirmation mailer using devise.
I found out that my image and css is loaded in other email provider like hotmail. However, image/css in my mailer view is not loaded properly in gmail. I wonder why it only does not work in gmail. I put all CSS in inline style since I saw that I cannot add CSS files to mailer views.
In production.rb
, I set asset_host:
config.action_mailer.asset_host = ENV['DEFAULT_HOST']
Below is mailer code I have in Rails:
<body style="background-color: #F7F7F7;">
<div class="main wrapper clearfix">
<div style="border: 1px solid #e4e4e4;
border-radius: 5px;
margin: 50px auto;
padding: 20px 50px;
box-shadow: 0 1px 5px 0 rgba(0, 0, 0, 0.15);
background-color: white;
max-width: 700px;">
<div style="text-align:center">
<%= image_tag("logo-green.svg") %>
</div><br><br>
<div>
<p>Welcome <%= @user.first_name %>!</p>
<p style="line-height: 1.5">Let's confirm your email address. Click the button below to confirm your email.</p>
<%= link_to 'CONFIRM ACCOUNT',
confirmation_url(@resource, confirmation_token: @token),
style: "font-family: Raleway-SemiBold, sans-serif;
-webkit-font-smoothing: antialiased;
display: inline-block;
cursor: pointer;
text-decoration: none;
color: white;
letter-spacing: 1px;
padding: 13px 30px;
font-size: 0.8em;
color: #fff;
background-color: #00BA9B;
transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
transition-delay: 0.2s;
box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.26);
margin-top: 25px;
margin-bottom: 20px;
border-radius:" %>
<br><br>
<p style="line-height: 1.5">Thanks,<br>website <br> <a href="www.website.com" style="color: #00BA9B; text-decoration:none">www.website.com</a></p>
<br>
<p style="color:grey; font-size:11px;">P.S. If you didn't sign up for website, please ignore this email - apologies for the disturbance.<p>
</div>
</div>
</div>
</body>
I see that any of CSS on CONFIRM ACCOUNT
a tag is not working at all and <%= image_tag("logo-green.svg") %>
is not loaded at all too.
It is very strange that it works in hotmail but not in Gmail.
Would love to get any advice!
Upvotes: 0
Views: 845
Reputation: 81
I think you need to define your image as an attachment in your mailer. E.g. I have a mailer in app/mailers/customer_mailer.rb
that has a method verification_confirmation
. In this method I have the following line:
attachments.inline['logo.png'] = File.read(Rails.root.join("app/assets/images/logo.png"))
Now, in the view for this email (i.e. app/views/customer_mailer/verification_confirmation.html.erb
I can now embed the image like this:
<%= image_tag attachments['logo.png'].url, style: "width: 15vw; min-width: 200px;" %>
Upvotes: 1