我已将 aspx 页面转换为 html 并将其存储在 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);
}
}