Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send web page in email body with css

I am creating a report on an asp.net web page using an html table and asp.net lables. The finished report I have to send by email in the message body. I've done this with the following c# code:

public bool SendEMail(List<string> emailList, string strSubject, string strMessage, bool isHTML)
    {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(strFrom);
            //emailList is a list of email addresses to be sent to
            if (emailList != null && emailList.Count > 0)
                foreach (string em in emailList)
                {
                    msg.To.Add(em);
                }
            else
                return false;
            msg.Subject = strSubject;
            msg.Body = strMessage;
            msg.IsBodyHtml = isHTML;
            SmtpClient smtp = new SmtpClient(mailServer);
            smtp.Credentials = new System.Net.NetworkCredential(userName, usePass);
            smtp.Send(msg);
            msg.Dispose();
            return true;
        }

This works well but it only gets styles set within the form itself on each control individually. How can I incorperate css set in the html head or in a style sheet? Also is it possible to include skins?

like image 410
Dov Miller Avatar asked Mar 06 '12 12:03

Dov Miller


2 Answers

Take a look to this chart :

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

I would recommend you to use inline styles instead of adding an external css sheet

like image 95
tetuje Avatar answered Oct 14 '22 06:10

tetuje


styling html emails is a pain in the ass, with each client (gmail/hotmail/outlook/yahoo) applying their own styles to certain high level elements.

a good rule of thumb is to apply inline styles for example:

<span style="display:block; background:red;">blah</span>

have a look at campaign monitor to see which css rules work and litmus if you wish to take the pain out of the testing

like image 30
ncremins Avatar answered Oct 14 '22 06:10

ncremins