直接抓取網頁內容來發信

2012022917:31
        protected void Page_Load(object sender, EventArgs e)
        {
            string Student_Number = (!string.IsNullOrEmpty(Request["Student_Number"]) ? Request["Student_Number"] : "");
            
            string SendTo = WebConfigurationManager.AppSettings["SendTo"];
            string Title = "報名資料 - 學號:" + Student_Number;

            //抓取網頁內容
            string WebPath = WebConfigurationManager.AppSettings["WebPath"];
            string Url = WebPath + "List.aspx?Student_Number=" + Student_Number;
            WebRequest request = WebRequest.Create(Url);
            WebResponse response = request.GetResponse();
            Stream resStream = response.GetResponseStream();
            StreamReader sr = new StreamReader(resStream, System.Text.Encoding.UTF8);
            string Content = sr.ReadToEnd();
            resStream.Close();
            sr.Close();

            //發送信件
            string[] ToAll = SendTo.Split(";".ToCharArray());
            MailMessage newMail = new MailMessage();
            newMail.From = new MailAddress("XX旅行社-訊息通知 ");
            newMail.Priority = MailPriority.Low;
            newMail.BodyEncoding = System.Text.Encoding.UTF8;
            newMail.IsBodyHtml = true;
            newMail.Body = Content;
            foreach (string to in ToAll)
            {
                if (to.Length > 0)
                {
                    //加入指定的發信對象
                    newMail.To.Add(new MailAddress(to));
                }
            }
            newMail.To.Add(new MailAddress(Studen_Email));  //加入報名者的Email,一併發送
            newMail.Subject = Title;
            SmtpClient sc = new SmtpClient(ConfigurationSettings.AppSettings["SmtpServer"]);
            sc.Send(newMail);

            //發信完成,轉址到指定頁面
            Server.Transfer("List.aspx?Student_Number=" + Student_Number);
        }