Css and ActionMailer

Hello!

I’ve been trying to send html with css emails with ActionMailer, the
html part goes perfect, but the css doesn’t seem to work.
I have tried using

and also embeding it in the html, like this:

body { .... }

but none of those ways seems to work :’(

Any ideas?

I’m using Rails 2.0.2

Thx in advance

Most email clients block links to external stylesheets. So your
embedding version should work. I use this all the time so I’m not
certain where you’re getting blocked. Have you tested it across
multiple email clients? What does the raw email body look like? As you
expect or is the css getting pared out?

Have you tested it across multiple email clients?

I’m sending the email to my gmail account (this one) and it doesn’t
render
the css.
Now that you mention it I’m trying to watch it through thunderbird
(using
POP in my gmail account) and the embeded version works nicely. Any guess
why
gmail doesnt show the mail correctly?

What does the raw email body look like? As you
expect or is the css getting pared out?

Yes, there are no characters scaped or something strange in the mail, at
least, nothing that i noticed.

Here is a paste of the “Show Original” from gmail:


    Delivered-To: [email protected]
    Received: by 10.141.197.3 with SMTP id z3cs234339rvp;
            Sun, 20 Jan 2008 12:59:51 -0800 (PST)
    Received: by 10.114.167.2 with SMTP id

p2mr3929238wae.78.1200862791200;
Sun, 20 Jan 2008 12:59:51 -0800 (PST)
Return-Path: [email protected]
Received: from pants.dreamhost.com (pants.dreamhost.com [
66.33.216.244])
by mx.google.com with ESMTP id
k39si13460028wah.4.2008.01.20.12.59.50;
Sun, 20 Jan 2008 12:59:51 -0800 (PST)
Received-SPF: neutral (google.com: 66.33.216.244 is neither
permitted nor denied by domain of [email protected])
client-ip=66.33.216.244;
Authentication-Results: mx.google.com; spf=neutral (google.com:
66.33.216.244 is neither permitted nor denied by domain of
[email protected])
[email protected]
Received: from smarty.dreamhost.com (smarty.dreamhost.com [
208.113.175.8])
by pants.dreamhost.com (Postfix) with ESMTP id
A3D8314C009
for [email protected]; Sun, 20 Jan 2008 12:59:50 -0800
(PST)
Received: from oj.dreamhost.com (oj.dreamhost.com
[208.97.183.24])
by smarty.dreamhost.com (Postfix) with ESMTP id
436CFEE298
for [email protected]; Sun, 20 Jan 2008 12:59:49 -0800
(PST)
Received: from localhost.localdomain (localhost [127.0.0.1])
by oj.dreamhost.com (Postfix) with ESMTP id 3F8BAD070E
for [email protected]; Sun, 20 Jan 2008 12:59:49 -0800
(PST)
Date: Sun, 20 Jan 2008 12:59:49 -0800
From: [email protected]
To: [email protected]
Message-Id: [email protected]
Subject:
=?utf-8?Q?=5bVDC_newsletter_n=c2=ba=32=35=5d_Lorem_Ipsum?=
Mime-Version: 1.0
Content-Type: text/html; charset=utf-8

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html;

charset=iso-8859-1" />
Lorem Ipsum

    <style type="text/css">
    * { padding: 0; margin: 0; }
    body {
     font-family: Arial, Helvetica, sans-serif;
     font-size: 14px;
    }
    #wrapper {
     margin: 0 auto;
     width: 800px;
     border: solid;
     border-width: 1px;
     border-color: #306;
    }

    #wrapper a{text-decoration:underline; color: #330066; 

font-weight:
bold;}
#wrapper a:hover{text-decoration:none; color: #cc00cc;}
#wrapper a:visited{color: #996699;}

    #cabecera {
     width: 800px;
    }
    #navegacion {
     width: 780px;
     color: #ccf;
     padding: 10px;
     margin: 0px;
     background: #306;
    /* border: solid;
     border-width: 1px;
     border-color: black; */
    }
    #boletin-info .fecha {text-align:left; float:left;}
    #boletin-info .numero { text-align:right; text-decoration:

underline;}

    #central {
     /*background: url(central-1-2-col.gif);*/
     overflow: auto; /* Paul O Brien Fix for IE www.pmob.co.uk */
     width: 760px;
     padding: 10px 20px 10px 20px;
    /* border: solid;
     border-width: 1px; */
    }

    #enlaces {text-align:center; font-size: 16px; padding: 20px 0px 

20px
0px;}
#enlaces li{list-style-type:none;}

    #pie {
     width: 800px;
     color: #306;
     background: #fff;
     border: solid;
     border-width: 2px 0px 0px 0px;
     overflow: auto; /* linea magica, sino firefox hace cosas raras 

*/
font-size: 12px;
}

    #pie li{list-style-type:none;}

    .pie-izq{
     color:black;
     width: 390px;
     padding:5px;
     float:left;
     display: inline; /* linea magica, sino firefox hace cosas raras 

*/
text-align: right;
}

    .pie-dch{
     width: 390px;
     padding:5px;
     float:right;
     display: inline; /* linea magica, sino firefox hace cosas raras 

*/
text-align: left;
}
#disclaimer{
padding: 10px 80px 10px 80px;
font-size: 10px;
background: #330066;
color: #ccf;
text-align: center;
}

    #disclaimer a{ color: #969; font-weight: bold;}
    #disclaimer a:visited{ color: #ccc; }
    #disclaimer a:hover{ color: #ccf; text-decoration: none;}
    </style>

    </head>

    <body>

    <!-- Begin Wrapper -->
    <div id="wrapper">

    <!-- Begin cabecera -->
    <div id="cabecera">
      <img alt="Facultad de Informatica - Newsletter" src="

http://boletin.yoteinvoco.com/images/cabecera.png" />

          <!-- Begin navegacion -->
    <div id="navegacion">
      <span id="boletin-info">
        <p class="fecha">5/1/2008</p>
        <p class="numero">boletin nº 25</p>
      </span>
    </div>
    <!-- End navegacion -->
    <div id="central">
      <h2>Lorem Ipsum</h2>
      <p class="cuerpo">
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Maecenas est dui, tempus quis, ullamcorper non, dictum vel, ligula.
Quisque
iaculis leo eget turpis. In a elit id elit semper fermentum. Mauris
tincidunt odio id diam. Nunc fringilla eleifend urna. Donec fermentum
scelerisque magna. Sed rhoncus. Nullam accumsan elementum ipsum.
Maecenas ac
purus. Nam gravida venenatis sem.



Nulla facilisi. Vestibulum pretium lectus semper odio
hendrerit
pharetra. Cras eget sapien. Aenean pretium eros id justo. Proin
pellentesque
dolor. Vivamus enim arcu, varius vel, elementum ac, tempor et, pede.
Donec
ac libero. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Integer nulla ante, consequat quis,
dictum at, faucibus eu, metus. Cras aliquam. Integer consequat hendrerit
odio.



Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas. Donec diam orci, tristique at,
bibendum
accumsan, egestas eu, diam. Nullam elementum nisl ac urna. Etiam
gravida.
Phasellus euismod est eu ante. Suspendisse potenti. Nulla auctor nisi.
Duis
ut ipsum ut lorem consectetuer accumsan. Donec posuere dui eu massa. In
condimentum ultrices nisi. Sed felis justo, adipiscing eu, ultrices
eget,
porttitor et, ante. Maecenas semper. Suspendisse ornare felis eget est.
Aliquam eu ligula quis mi tincidunt scelerisque. Sed viverra. Nam id
orci.



Suspendisse et libero. Cum sociis natoque penatibus et
magnis
dis parturient montes, nascetur ridiculus mus. Morbi augue metus,
interdum
id, egestas sed, congue a, nulla. Fusce in enim eget diam pretium
vestibulum. Class aptent taciti sociosqu ad litora torquent per conubia
nostra, per inceptos hymenaeos. Pellentesque a risus a lectus interdum
molestie. Nulla facilisi. Vivamus lectus tellus, cursus at, faucibus
vel,
ornare nec, purus. Vivamus non pede. Donec id augue. Nam sit amet augue.
Nunc et metus sit amet nisl consequat sagittis. Sed venenatis nibh quis
eros. Aenean viverra enim vel felis. Mauris mauris lorem, sodales ut,
pharetra in, sollicitudin quis, tortor.





      </ul>
    </div>
    <!-- End central -->




          <div id="pie">
            <div class="pie-izq">
              <ul>
                <li>Vicedecanato de Calidad</li>
                <li>Facultad de Informática</li>
                <li>U.P.M.</li>
              </ul>
            </div>
            <div class="pie-dch">
              <ul>
                <li><a href="http://www.fi.upm.es/?pagina=441">

Subdirector de Calidad y Acreditaciones-ETS de Ingenieros Informáticos (UPM)

  • http://www.fi.upm.es

  • http://www.upm.es





  • Vd. ha recibido este correo de forma automatica porque
    así
    lo ha solicitado si desea
    darse de baja del servicio y parar de recibir correos
    pinche
    aqui
    y siga los pasos indicados.

            </div>
            <!-- End Wrapper -->
          </body>
        </html>
    

    Gmail isn’t going to let you do something dangerous like that, lol.
    They don’t even let you see external images without saying yes first
    :slight_smile:

    On Jan 20, 3:21 pm, “Hassan S.” [email protected]

    On Jan 20, 2008 1:34 PM, kopf1988 [email protected] wrote:

    Gmail isn’t going to let you do something dangerous like that, lol.

    Are you suggesting that “inline CSS” is dangerous?? How so?

    In any case, I can assure you that the HTML emails I do for clients
    render just fine in Gmail :slight_smile:

    In my experience, inline CSS gives the best results across a variety
    of email clients.


    Hassan S. ------------------------ [email protected]

    If one has to have HMTL/CSS emails, go “1996” HTML. Use tables for
    layout. That sort of thing.

    Now I haven’t used this service but I saw it a while ago.
    http://www.mailchimp.com/add-ons/inboxinspector/
    “MailChimp Inbox Inspector - Check your email marketing campaigns with
    one easy click”
    It renders your email in different clients so you can see how they
    look.

    HTH
    John

    On Jan 20, 5:10 pm, “Hassan S.” [email protected]

    On Jan 20, 2008 12:45 PM, Alejandro R. [email protected] wrote:

    I’ve been trying to send html with css emails with ActionMailer, the
    html part goes perfect, but the css doesn’t seem to work.
    I have tried using

    <link href="http://url/stylesheets/layout.css" rel="stylesheet"

    /

    and also embeding it in the html,
    /
    but none of those ways seems to work :cry:

    In my experience, inline CSS gives the best results across a variety
    of email clients.

    FWIW,

    Hassan S. ------------------------ [email protected]

    Hi,

    I have a scenario where in my system is generating the mail and it is
    being sent via my gmail acc and it has an attachment as well with
    predefined text and all. But when the same mail is sent from the
    clients system, then in my attachment the disclaimer of the client
    company is coming in.
    Why is this happening. My emails should have the settings of my
    account but why does the client settings chip in even when emails are
    being sent out using my account.

    Any thoughts on this.

    Neha

    On Feb 19, 11:12 am, Patrick B. <rails-mailing-l…@andreas-

    I’m facing the same problem: sending an HTML mail formatted with an
    internal stylesheet be will displayed unformatted in some mail clients,
    i.e. GMail:

    Hello

    Instead, you have to use inline style (inside an HTML element):

    Hello