[ASP.NET]GridView Email寄送

摘要:[ASP.NET]GridView Email寄送

若是Asp.NET GridVieW要發送電子郵件Code,紀錄一下,
但若是要定時發送,可能要改用SSIS寄送
public void SendMail(){

        MailMessage Msg = new MailMessage();
        MailAddress fromMail = new MailAddress("System@nsp.com");
        Msg.From = fromMail;
        MailAddress toMail = new MailAddress("Karen.Ku@nsp.com");
        Msg.To.Add(toMail);
        Msg.Subject = "TestSendGridView";
        Msg.Body += "須申請假勤明細"+"
";
        String sGridview = GetGridviewData(GridView1);
        Msg.Body += sGridview;

        Msg.IsBodyHtml = true;
        NetworkCredential myCredit = new NetworkCredential("fab2mfg.cim", "Ff@@$$$123456");

        SmtpClient smtp = new SmtpClient("f2pchs.neosolarpower.com");
        smtp.Port = 25;
        smtp.Credentials = myCredit;
        //smtp.EnableSsl = true;
        smtp.Send(Msg);
    }


    public string GetGridviewData(GridView gv)
    {
        StringBuilder strBuilder = new StringBuilder();
        StringWriter strWriter = new StringWriter(strBuilder);
        HtmlTextWriter htw = new HtmlTextWriter(strWriter);
        gv.RenderControl(htw);
        return strBuilder.ToString();
    }
 public override void VerifyRenderingInServerForm(Control control)
    {

    }