Reputation: 2058
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?
Upvotes: 7
Views: 21357
Reputation: 1
Look at the implementation using AlternateViews, this will help you, if you are dynamically generating email body, with styles.
http://microsoft.com/....alterviews.aspx
Upvotes: 0
Reputation: 3271
This can be done just the same way you'd set the css on a web page. In the message body, you can use a fully formed html document including head tags which can link to an external stylesheet. As long as the css is contained completely within the document, or a full URL is used in the link, it should be fine.
Upvotes: 0
Reputation: 9200
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
Upvotes: 4
Reputation: 289
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
Upvotes: 12