How to send webpage in email using css

I am creating a report on an asp.net webpage using an html table and asp.net tables. A finished report that I have to send by email in the body of the message. I did 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 only sets the styles set inside the form itself on each control separately. How can I embed css in html-head or in a stylesheet? Can I also turn on skins?

+4
source share
4 answers

Take a look at this diagram:

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

I would recommend using inline styles instead of adding an external css sheet

+9
source

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

A good rule is to use inline styles, for example:

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

look at the campaign monitor to see which css rules work, and litmus if you want to take the pain off testing

+3
source

This can be done in the same way that you installed css on a web page. In the body of the message, you can use a fully-formed html document, including header tags that can refer to an external stylesheet. As long as css is fully contained in the document, or the full URL is used in the link, this should be fine.

0
source

Look at the implementation with AlternateViews, this will help you if you dynamically create an email body with styles.

http://microsoft.com/....alterviews.aspx

0
source

Source: https://habr.com/ru/post/956478/


All Articles