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.
Asked
Active
Viewed 938 times
0
-
did you try inline style – sertsedat Mar 25 '16 at 09:31
-
I can not add because css is very complex and how can I add css to each tag. – Asnad Atta Mar 25 '16 at 09:32
-
1set css files path with server url if you project is deployed somewhere like : `http://project.herokuapp.com/assets/style.css` otherwise you will have to go for inline styles – Muhammad Ali Mar 25 '16 at 09:32
-
1is there any option available just like mandrill to allow css like in mandrell we have inline_css option. – Asnad Atta Mar 25 '16 at 09:34
-
1You can check out this gem premailer-rails which may offer what you need to – Hieu Pham Mar 25 '16 at 09:43
3 Answers
3
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'

Lee Dykes
- 1,017
- 8
- 16
0
Gemfile.rb
gem 'roadie-rails'
than inside of x_mailer.rb
include Roadie::Rails::Automatic

Travis Delly
- 1,194
- 2
- 11
- 20