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

2年前 (2022) 程序员胖胖胖虎阿
309 0 0

  System.Web.Mail(.NET1.x)

1.引用:
【Vegas原创】System.Net.Mail(.net2.0)或System.Web.Mail(.NET1.x) 发送邮件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

 

相关文章

暂无评论

暂无评论...