How to send HTML email with styles in rails
I want to know how we can send webpage (HTML page) as an email. I want to add s开发者_StackOverflow社区tyle in a html page like Images or some table formatting. I want to know that should I add style in my "conta.text.html.erb" or I can add CSS in it?
It's not a best pratice to add file with your CSS in an email. You need define your CSS inline in your email.
About Asset, it's better to host it in your website. You can link it in your email. Your email is lighter with this technique.
Some item's that i've found help in email readability across multiple clients:
Use tables for layout and element positioning
Don't include the images directly in your email rather reference them from your site src= "http://example.com/myimage.jpg"
Always send a text.plain backup in case your end user's client cannot read html (such as the military).
Use inline styles as recommended by sihingara, if you must require css and or js be sure you put in an absolute path so src = "http://example.com/myjavascript.js" instead of src= "/myjavascript.js"
Hope this helps, if not ask a followup comment.
As mentioned above, HTML emails do not play well with style blocks that are declared out-of-line. Webmail clients in particular tend to strip them out completely.
Best practice is to only use inline styles; for this I highly recommend the Premailer Plus gem which will in-line all the styles in a block of html. Depending on your workflow; you can either do this when you build the templates or as a pre-processor before each email is sent.
精彩评论