简体   繁体   English

如何使用css在电子邮件正文中发送网页

[英]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. 我正在使用html表和asp.net标签在asp.net网页上创建报告。 The finished report I have to send by email in the message body. 我必须通过电子邮件在邮件正文中发送完成的报告。 I've done this with the following c# code: 我用以下c#代码完成了这个:

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? 我怎样才能在html头部或样式表中包含css集? Also is it possible to include skins? 还可以包括皮肤吗?

Take a look to this chart : 看看这张图表:

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

I would recommend you to use inline styles instead of adding an external css sheet 我建议你使用内联样式而不是添加外部css表

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. 样式化HTML电子邮件是一个痛苦的屁股,每个客户端(gmail / hotmail / outlook / yahoo)将自己的样式应用于某些高级元素。

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 如果您希望从测试中消除痛苦,请查看活动监视器以查看哪些css规则有效并且有石蕊

Look at the implementation using AlternateViews, this will help you, if you are dynamically generating email body, with styles. 使用AlternateViews查看实现,如果您使用样式动态生成电子邮件正文,这将有助于您。

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

This can be done just the same way you'd set the css on a web page. 这可以像在网页上设置css一样完成。 In the message body, you can use a fully formed html document including head tags which can link to an external stylesheet. 在邮件正文中,您可以使用完整格式的html文档,包括可以链接到外部样式表的头标记。 As long as the css is contained completely within the document, or a full URL is used in the link, it should be fine. 只要css完全包含在文档中,或者链接中使用了完整的URL,它就应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM