0

我已将 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);
    }
}
4

1 回答 1

0

我相信您应该查看以下链接以了解邮件发送。

http://csharp.net-informations.com/communications/csharp-email-attachment.htm

http://www.codeproject.com/Articles/10828/Sending-Email-with-attachment-in-ASP-NET-using-SMT

您还必须选中在运行时生成 HTML 文件并作为电子邮件附件发送以生成 HTML

快乐编码!

于 2012-09-13T08:50:39.140 回答