简体   繁体   English

从C#邮寄asp.net页面

[英]Mail an asp.net page from c#

I want to mail an asp.net page from c#. 我想从c#寄出一个asp.net页面。 well it is questioned widely and I saw bulk of questions like that on stackoverflow too. 好吧,它受到了广泛的质疑,我在stackoverflow上也看到了很多类似的问题。 But I have few problems that I'm not getting the solutions 但是我有一些问题,我没有得到解决方案

What Itried 什么迭代
many example. 很多例子。 below are few 下面是几个

using (System.IO.StreamReader reader = System.IO.File.OpenText( Server.MapPath("~/About.aspx"))) // Path to your 
      {                                                         // HTML file
        string fromAddress = "from@yahoo.com";
        string toAddress = "to@yahoo.com";
        System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage(fromAddress, toAddress);
        myMail.Subject = "HTML Message";
        myMail.IsBodyHtml = true;
        myMail.Body = reader.ReadToEnd();  // Load the content from your file...
                //...

        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.mail.yahoo.com");
        smtp.Credentials = new System.Net.NetworkCredential("from@yahoo.com", "password");
        smtp.Send(myMail);

        }

But this is giving me this output. 但这给了我这个输出。 在此处输入图片说明

Well you noticed that it is without css. 好吧,您注意到它没有CSS。
Can I mail an entire asp.net page or do I need to write my code in c# with inline css? 我可以邮寄整个asp.net页面,还是需要使用内联CSS在C#中编写代码? Or do I need to create a control with a patern and send it? 还是我需要创建一个带有模式的控件并将其发送?

You are trying to send unprocessed aspx file. 您正在尝试发送未处理的aspx文件。 This cannot be successful. 这不会成功。 You need to process this page (I dont remember what method to use), and dont forget about inline css. 您需要处理此页面(我不记得要使用哪种方法),并且不要忘记内联CSS。 So bassicaly you need a new page. 因此,您需要一个新页面。 And if you need a new page, you can do it with pure html, not in asp. 而且,如果您需要一个新页面,则可以使用纯HTML而不是asp。

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

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