vs.net 2003 和2005中邮件发送比较

原创 2007年09月20日 14:34:00


        #region Send Email With Smtp Include Two Edit(vs.net 2003 & vs.net 2005)

        #region SendMail with vs.net 2003 (System.Web.Mail Class)
        /*
        public void SendMail(Page pPage, string pToMail, string pSubject, string pBody)
        {
            try
            {
                MailMessage mailObj = new MailMessage();
                mailObj.From = "tek-service@163.com";
                mailObj.To = pToMail;
                mailObj.Cc = "tek.vanilla@163.com,Vanilla.huang@tek.com.cn";
                mailObj.Subject = pSubject;
                mailObj.Body = pBody;
                mailObj.BodyFormat = MailFormat.Text;

                mailObj.Priority = MailPriority.High;
                //mailObj.Attachments.Add(new MailAttachment("c://test.doc"));

                mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");   //basic   authentication    
                mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "tek-service");   //set   your   username   here    
                mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "tek");   //set   your   password   here    

                SmtpMail.SmtpServer = "smtp.163.com";
                SmtpMail.Send(mailObj);
            }
            catch
            {
                ShowMessage(pPage, "邮件地址填写不正确或者网络不通!");
            }
        }*/
        #endregion

        #region SendMail with vs.net 2005(System.Net.Mail Class)
        public void SendMail(Page pPage, string pToMail,string pCC, string pSubject, string pBody,string pAttachment)
        {
            try
            {
                MailAddress mailTo = new MailAddress(pToMail);
                MailAddress mailFrom = new MailAddress("abc@126.com");
                MailMessage mailObj = new MailMessage(mailFrom, mailTo);
                if (pCC != "" || pCC != String.Empty)
                {
                    mailObj.CC.Add(pCC);
                }
               
                mailObj.Subject = pSubject;
                mailObj.Body = pBody;
                if (pAttachment != String.Empty || pAttachment != "")
                {
                    mailObj.Attachments.Add(new Attachment(pAttachment));
                }
                mailObj.IsBodyHtml = true;
                mailObj.BodyEncoding = Encoding.Default;
                //mailObj.IsBodyHtml = false;

                NetworkCredential credential = new NetworkCredential("abc", "123333");
                SmtpClient client = new SmtpClient("smtp.126.com");
                client.Credentials = credential;
                client.Send(mailObj);
                ShowMessage(pPage, "发送成功!");
            }
            catch
            {
                ShowMessage(pPage, "邮件发送失败!");
            }
        }

        public void SendMail(Page pPage,string sFromMail, string sToMail, string sCC, string sSubject, string sBody, string sAttachment,string sUserName,string sPassword,string sSmtpServer)
        {
            try
            {
                MailAddress mailTo = new MailAddress(sToMail);
                MailAddress mailFrom = new MailAddress(sFromMail);
                MailMessage mailObj = new MailMessage(mailFrom, mailTo);
                if (sCC != "" || sCC != String.Empty)
                {
                    mailObj.CC.Add(sCC);
                }
                mailObj.Subject = sSubject;
                mailObj.Body = sBody;
                if (sAttachment != String.Empty || sAttachment != "")
                {
                    mailObj.Attachments.Add(new Attachment(sAttachment));
                }
                mailObj.IsBodyHtml = true;
                mailObj.BodyEncoding = Encoding.Default;

                NetworkCredential credential = new NetworkCredential(sUserName, sPassword);
                SmtpClient client = new SmtpClient(sSmtpServer);
                client.Credentials = credential;
                client.Send(mailObj);
                ShowMessage(pPage, "邮件已成功发送发送到:"+sToMail+"!");
            }
            catch
            {
                ShowMessage(pPage, "邮件发送失败!");
            }
        }
        #endregion

        #endregion
 

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

安装和配置VS.NET 2003和SQL SERVER 2005

1、首先安装IIS。 工具/原料 环境:windows xp 步骤/方法 1 先在百度找到IIS 6.0,然后下载下来,当然其它的版本也可以,我这个是为了凑合系统。  ...

VS.NET 2003 + MySQL Server 5.1 编写第一个MySQL控制台程序 (三)

继续向下学。。。 接下来,我们要学习编写一个错误处理函数。咱们的代码中都是通过检查调用的 MySQL 库函数的返回值来判断函数调用是否成功。返回指针的函数调用,判断返回值是否是一个空指针(NULL...

开源:VS.NET打印思想与2003/5DataGrid、DataGridView及二维数据如ListView等终极打印实现(转)

转自:http://blog.csdn.net/flygoldfish/archive/2006/02/06/592790.aspx 关  键  字:VS.NET、打印、DataGrid、DataG...

VS.NET 2003 使用External Tool配置打开文件目录

在Tools-External Tools...打开External Tools对话框,增加如下配置: Title: openfolder Command: explorer Argumen...

VS.NET 2003 + MySQL Server 5.1 编写第一个MySQL控制台程序 (一)

首先,我们必须下载 MySQL Server 5.1 。是那种完整安装包,安装后在 MySQL Server 的安装目录里要有 include 和 lib\debug 文件夹,其中必须包含开发 MyS...

win7 vs.net2003 调试webservice 无法单步执行

现有项目是用vs.net2003开发,客户端是winform,服务端是webservice,两个项目在一个解决方案中。原来用的是win2003,可以在解决方案中单步执行程序调试,遇到webservic...

VS.net 2003 打开Web项目失败的解决方法

几个月前我打开一个Web项目,VS 2003居然告诉我以下信息: Refreshing the project failed. Unable to retrieve folder informat...

用VS.NET2003制作WEB应用程序的安装包

利用vs.net2003来制作一个安装程序是非常的方便的,既使是制作一个web应用程序的安装程序也是如此。仅仅简单的几个步骤就可以完成。 首先,创建一个安装和部署项目。步骤如下: 1.在"解决...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)