3

I am not able to apply my CSS styles to an email which I am sending it as a html format. If I save the ODS output to a local file, I am able to apply my CSS styles.

Could someone help me on how to pass the CSS styles in an email step?

Here is the code I used:

FILENAME SETMAIL EMAIL TO=("tester.first@somedomain.com")
         SUBJECT = "This is a test email with applied CSS HTML styles to email " 
         TYPE="text/html" 
         CONTENT_TYPE='text/html' ;
         ODS HTML BODY=setmail
         CSSSTYLE="D:\\myStyles_EMAIL.css";

TITLE "Be focused !! ";      
PROC PRINT DATA=DODEV.RECENT_HIGH_VOL_ORDERS noobs label;
RUN;
ODS HTML CLOSE;
ODS LISTING;

Thanks in advance.

Robert Penridge
  • 8,424
  • 2
  • 34
  • 55
Naga Vemprala
  • 718
  • 3
  • 16
  • 38
  • Just tried running your code on my machine and it worked as expected. I did change the style to the banker style that is bundled with EG (i.e. `CSSSTYLE="C:\Program Files\SASHome\SASEnterpriseGuide\5.1\Styles\banker.css"`). Perhaps there is a problem with the .css file you are using. – Robert Penridge Jun 11 '15 at 14:12

2 Answers2

1
proc template; 
    define style styles.MyMail;
    parent= styles.journal; 
    style body /
        fontfamily="Arial, Helvetica, Sans-serif"
        fontsize= 2
        fontweight=medium
        fontwidth=normal
        color=blg
        backgroundcolor=white
        marginleft=8pt
        marginright=8pt;
    style header /
        fontfamily="Arial, Helvetica, Sans-serif"
        fontsize= 4
        fontweight=bold
        fontstyle=roman
        bordercolor=black
        textalign=center
        backgroundcolor=CX00365B
        color=white;
    style Data / 
        fontfamily="Arial, Helvetica, Sans-serif"
        fontweight=medium
        fontsize=2
        fontstyle=roman
        color=black
        backgroundcolor=white;
    style SystemTitle / 
        fontfamily="Arial, Helvetica, Sans-serif"
        fontweight=bold
        fontsize=6
        fontstyle=roman
        textalign=left
        color=white
        backgroundcolor=CX00365B;
    style SystemTitle2 / 
        fontfamily="Arial, Helvetica, Sans-serif"
        fontweight=bold
        fontsize=4
        fontstyle=roman
        textalign=left
        color=white
        backgroundcolor=CX00365B;
    style SystemTitle3 / 
        fontfamily="Arial, Helvetica, Sans-serif"
        fontweight=medium
        fontsize=2
        fontstyle=roman
        textalign=left
        color=black
        backgroundcolor=white;
     end;
run;

%MACRO SEND_EMAIL_NOTIFICATION(); 

%IF &NUM_CONDS > 0 %THEN

     %DO;       
           FILENAME SETMAIL EMAIL TO=( "hhhhhhhh@xyz.com")
                SUBJECT = "Alert: XXXXXXXX" 
                TYPE="text/html" 
           CONTENT_TYPE='text/html';
           ODS html3  BODY=SETMAIL 
           STYLE=MYMAIL;

           TITLE "Some title 1 ";
           TITLE2 As of &RUN_TIME;
           TITLE3 A total of &NUM_XYZz Some titles, since the last report;
           TITLE4 " " ;

           PROC PRINT DATA=DEV.RECENT_DS noobs label;
           RUN;
           ODS HTML3 CLOSE;
           ODS LISTING;
     %END;
%MEND;

%SEND_EMAIL_NOTIFICATION();

Finally completed the requirement by creating my own style. Rather than using the CSSSTYLE. Not sure how to make the CSSSTYLE work. I think the .msg and .html outputs are causing the issue.

Naga Vemprala
  • 718
  • 3
  • 16
  • 38
0

Try using ODS HTML3. This embeds the style information directly into the HTML elements so that no CSS is used to render (all the style information is stated repeatedly and explicitly within each HTML tag).

This ODS destination is great for backwards compatibility. And seeing as the HTML rendering engine used by Outlook is actually the MS Word Engine, a lot of backwards compatability is required.

Here's the ODS HTML3 doc link: http://support.sas.com/documentation/cdl/en/odsug/61723/HTML/default/viewer.htm#a002596390.ht

Not all HTML formatting is supported by a lot of email clients though. Here's some useful links to give you a good background of what can and can't be done, and what is and isn't supported:

http://24ways.org/2009/rock-solid-html-emails

http://www.emailology.org

http://www.campaignmonitor.com/css/

HTML email align text

Community
  • 1
  • 1
Robert Penridge
  • 8,424
  • 2
  • 34
  • 55
  • even if I use html3 the CSSSTYLE is getting ignored. My concern is even when there is CSSSTYLE specified, why am I seeing normal email output? – Naga Vemprala Jun 11 '15 at 01:19
  • @NagaVemprala I should also add that in my testing, `ODS HTML3` was able to apply more of the styles than `ODS HTML`, so I would still recommend using it. – Robert Penridge Jun 11 '15 at 14:58
  • Thank you for taking your time for me Robert. I am highly indebted to you. But unfortunately, I think all the fancy formatting features, I am not able to embedd in the email. Could be issue with .html vs .msg . I also tried the code with banker.css but still it is not that fancy. Borders itself are not coming. Also, HTML and HTML3 are not making much difference when we send the output to email. – Naga Vemprala Jun 11 '15 at 15:09
  • small correction. HTML3 is much better. But still borders are not coming :( – Naga Vemprala Jun 11 '15 at 16:22
  • @NagaVemprala Ok so it sounds like at least the CSS is registering now, it's just that you're not getting the look you need. Take a look at the standards guide on the emailology link. It shows what is supported by the tag etc. You may need to modify your .css file so that it only uses atributes supported by the tag to get the look you require. – Robert Penridge Jun 11 '15 at 17:57
  • .Data { font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: normal; font-style: normal; color: #000000; background-color: #FFFFFF; border: 5px solid #000000; } color is changing if I change the value. But border is not appearing. – Naga Vemprala Jun 11 '15 at 18:00
  • Rather than using the .css file, finally completed my requirement using PROC TEMPLATE – Naga Vemprala Jun 12 '15 at 00:33
  • @NagaVemprala Be sure to post the solution then and mark it as accepted so that others may benefit from it. – Robert Penridge Jun 12 '15 at 17:02
  • My apologies @Robert-Penridge, posted the answer today. – Naga Vemprala Jun 15 '15 at 23:02