• 【Vegas原创】System.Net.Mail(.net2.0)或System.Web.Mail(.NET1.x) 发送邮件


      System.Web.Mail(.NET1.x)

    1.引用:
    using System.Web.Mail; 


    2.
      //Mail  
                    MailMessage mailObj = new MailMessage();
                    StringWriter sWriter 
    = new StringWriter();
                    HtmlTextWriter htmlWriter 
    = new HtmlTextWriter(sWriter); //眕涴跺霜濬釬峈統杅懂輛俴換怀杅擂﹝
                    DataGrid1.RenderControl(htmlWriter);
                    StringWriter s2Writer 
    = new StringWriter();       //DataGrid2
                    HtmlTextWriter htmlWriter2 = new HtmlTextWriter(s2Writer);
                    DataGrid2.RenderControl(htmlWriter2);
                    StringWriter s3Writer 
    = new StringWriter();   //DataGrid3
                    HtmlTextWriter htmlWriter3 = new HtmlTextWriter(s3Writer);
                    DataGrid3.RenderControl(htmlWriter3);
                    mailObj.From 
    = " "//寄件人
                    mailObj.To = " ";   //收件人
                    mailObj.Bcc = " ";  //彶躇璃萵璃腔華硊
                    mailObj.Subject = "(P1P0) Summary Daily KPI Report";  //主旨
                    mailObj.Body = mailObj.Body + "            <table>";
                    mailObj.Body 
    = mailObj.Body + "                <tr>";
                    mailObj.Body 
    = mailObj.Body + "                    <font size='3'  face='Broadway BT'>Summary Report--P1P0</font>";
                    mailObj.Body 
    = mailObj.Body + "                </tr>";
                    mailObj.Body 
    = mailObj.Body + "                <tr>";
                    mailObj.Body 
    = mailObj.Body + "    <font face='Xirod' ><u>&nbsp;&nbsp;&nbsp;";
                    mailObj.Body 
    = mailObj.Body + "DT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    mailObj.Body 
    = mailObj.Body + "</u></font>";
                    mailObj.Body 
    = mailObj.Body + "                </tr>";
                    mailObj.Body 
    = mailObj.Body + "            </table>";
                    mailObj.Body 
    = mailObj.Body + s3Writer.ToString() + sWriter.ToString() + "&nbsp;&nbsp;" + s2Writer.ToString() + "";  //蔚霜濬腔囀釬峈蚘璃腔淏恅窒煦
                    mailObj.BodyFormat = MailFormat.Html;  //跡宒趙峈html跡宒
            
                    
    try
                    {
                        SmtpMail.SmtpServer 
    = "***";
                        SmtpMail.Send(mailObj); 
    //覃蚚SmtpMail濬懂楷冞蚘璃
                    }
                    
    catch (Exception pp)
                    {
                        Response.Write(pp.Message);
                    }
                    Label1.Text 
    = DateTime.Now.ToString() + "楷冞傖髡ㄐ";
                }

                
    catch (Exception ex)  //11/10add 
                {

                    SaveError(ex, 
    this.Context, this.Request);//add
                }

    System.Net.Mail(.net2.0)
            Public Function SendMail(ByVal MailBody As StringByVal MailSubject As StringByVal MailTo As StringAs String
                
    REM 此处mail接收者,不另加auo.com。

                
    Dim TheMailMessage As New System.Net.Mail.MailMessage
                
    Dim SM As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient

                
    REM Mail发送者
                TheMailMessage.From = New System.Net.Mail.MailAddress("持续改善系统<**>")

                
    REM Mail接收者
                TheMailMessage.To.Clear()
                
    'TheMailMessage.To.Add(adr(MailTo))
                TheMailMessage.To.Add(New System.Net.Mail.MailAddress("Vegas Lee<**>"))
                
    REM Mail内容
                TheMailMessage.Body = MailBody

                
    REM Mail标题
                TheMailMessage.Subject = MailSubject

                
    REM Mail格式
                TheMailMessage.IsBodyHtml = True

                
    REM Mail编码
                TheMailMessage.BodyEncoding = System.Text.Encoding.UTF8

                
    REM Mail服务器
                SM.Host = ConfigurationSettings.AppSettings("SmtpServer")


                
    REM 发送Mail
                SM.Send(TheMailMessage)


            
    End Function
  • 相关阅读:
    一种JavaScript的设计模式
    ADO.Net之使用DataRead Or DataSet
    求助:彻夜难眠的问题
    ASP.NET的全球化配置
    ADO.NET和.NET框架中的数据管理[转]
    javascript实现datagrid客户端checkbox列的全选,反选
    下载文件出现提示框或者直接显示在浏览器中
    Visual Studio .NET已检测到指定的Web服务器运行的不是ASP.NET 1.1 版..(转)
    网站优化的十大奇招妙技
    关键字加亮JS方法
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744657.html
Copyright © 2020-2023  润新知