2012-09-13 45 views
0

我已將aspx頁面轉換爲html,並將hv存儲在var myPageHTML中。這裏是我正在使用的代碼...但我想發送HTML部分作爲電子郵件作爲附件或作爲郵件的正文。請幫忙。這裏是我正在使用的代碼...但我想發送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); 
    } 
} 
+1

什麼問題?你的具體問題是什麼?請充實你的問題,並給它一個更有用的標題。只包括相關的代碼。 –

+1

您可以將HTML內容保存到服務器中的某個頁面,並使用MailAttachment將其附加到該頁面 –

+0

是否要將HTML代碼的正文從HTML代碼發送到服務器端? – RL89

回答

0
+0

如何將html頁面保存到服務器的其他頁面中。請解釋 – user1665707

+0

@ user1665707請檢查以上答案我爲您添加了一個新鏈接 – Ravia

+0

@ user1665707請同時投票回答 – Ravia

相關問題