ruby-on-railsruby-on-rails-4gmailsendgridsendgrid-ruby

How to make css available for gmail using sendgrid


I am using Sendgrid api for my rails application to send email but in gmail is not supporting the css written within head tag what should I do to make css working.


Solution

  • Fortunately, this is unrelated to your use of SendGrid.

    According to FreshInbox, Gmail is unique amongst the major web mail clients in that it is completely incompatible with normal selectors within style tags within the head. This is due to the fact that it changes all of the classes and ids in your emails. You can get around this by using non-standard selectors.

    Typically though, developers work around this by using in-line styles. As bwest mentioned, the premailer-rails gem can help you accomplish this by automatically including your styles from a stylesheet as in-line. It's very simple to use, just add nokogiri and premailer-rails to your Gemfile:

    gem 'nokogiri'
    gem 'premailer-rails'