How To send Webpage as Email Message?

此生再无相见时 提交于 2020-01-06 08:39:17

问题


I want to send Email and it's Content should be a well Designed aspx Page. But the aspx page should not be sent as a Hyper-Link it should be shown as message Content?

Can It is Possible if ay suggession Please Reply...

Mohammed


回答1:


you can get the html of the page into a string with a web request like this:

WebRequest request;
string text;
        string url = "UrlToGet";
        request = (HttpWebRequest)
            WebRequest.Create(url);
        using (WebResponse response = request.GetResponse())
        {
            using (StreamReader reader =
                new StreamReader(response.GetResponseStream()))
            {
                text = reader.ReadToEnd();
            }
        }



回答2:


An aspx page is interpreted by the server and rendered to Java-script and html. Who will be doing this in that case? This is (currently) not possible.

The only thing you can do is got to html and write your message in html - so you have the looks but not the functionality.

hth

Mario




回答3:


you can do like this.....

private void Page_Load(object sender, System.EventArgs e)
{
    MailMessage mail = new MailMessage();
    mail.To = "me@mycompany.com";
    mail.From = "you@yourcompany.com";
    mail.Subject = "this is a test email.";
    string url = "http://www.microsoft.com";
    mail.Body = HttpContent( url );
    mail.BodyFormat = MailFormat.Html;
    mail.UrlContentBase = url;
    SmtpMail.SmtpServer = "localhost";  //your real server goes here
    SmtpMail.Send( mail );
}
//screen scrape a page here
private string HttpContent( string url )
{
    WebRequest objRequest= System.Net.HttpWebRequest.Create(url);
    StreamReader sr =  new StreamReader( objRequest.GetResponse().GetResponseStream() );  
    string result = sr.ReadToEnd();
    sr.Close();
    return result;
}


来源:https://stackoverflow.com/questions/6881528/how-to-send-webpage-as-email-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!