这是我正在使用的代码...但我想将html部分作为电子邮件发送。

时间:2012-09-13 08:32:15

标签: asp.net email

我已将aspx页面转换为html,并将hv存储在var myPageHTML中。这是我正在使用的代码...但我想将html部分作为电子邮件发送为附件或邮件正文。请帮忙。

    //this method on providing the url of the webpage copies the image of that webpage.

    protected void Button1_Click(object sender, System.EventArgs e)
    {
{
    WebClient myClient = new WebClient();
    string myPageHTML = null;
    byte[] requestHTML; 
    // Gets the url of the page
    string currentPageUrl = Request.Url.ToString();

    UTF8Encoding utf8 = new UTF8Encoding();

    // by setting currentPageUrl to www.yahoo.com it will fetch the source (html) 
    // of the yahoo.com and put it in the myPageHTML variable. 

   // currentPageUrl = "http://www.yahoo.com"; 

    requestHTML = myClient.DownloadData("http://localhost:31788");

    myPageHTML = utf8.GetString(requestHTML); 

    Response.Write();

     try
        {
             SendMail();
        }
        catch (Exception) { }
    }


protected void SendMail()
    {
        var userName = " from email";

        var toAddress = YourEmail.Text.ToString();

        const string Password = "password";

        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Question: \n" + Comments.Text + "\n";

        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "10.238.52.880";
            smtp.Port = 25;
            smtp.EnableSsl = false;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(userName, Password);
            smtp.Timeout = 20000;
        }
        smtp.Send(userName, toAddress, subject, body);
    }
}