gweber

每一缕清新的阳光都值得珍惜,每一首歌都有最美丽的旋律,每一个生命都应该受到尊重。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

asp.net发送邮件的方式不少,我经常用这样两种:
一,System.Web.Mail 和System.Web.Util

public static void SendMail(string from , string to, string subject, string body)
        
{
            MailMessage email 
= new MailMessage();
            email.From  
= from;
            email.To 
= to;
            email.Subject  
= subject;
            email.Body 
= body;
            SmtpMail.Send(email);    
        }
二 ,利用组件 adodb和cdo
public static void CDOsendmail(string from, string to, string subject, string body, string userName, string password, string smtpServer)
        
{
            
                CDO.Message Msg 
= new CDO.Message();
                Msg.From 
= from;
                Msg.To 
= to;
                Msg.Subject 
= subject;
                Msg.HTMLBody 
= "<html><body>"+body
                    
+"</body></html>";
                CDO.IConfiguration Config 
= Msg.Configuration;
                ADODB.Fields oFields 
= Config.Fields;
                oFields[
"http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
                oFields[
"http://schemas.microsoft.com/cdo/configuration/sendusername"].Value=userName;
                oFields[
"http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value=password; 
                oFields[
"http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
                oFields[
"http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
                oFields[
"http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value=smtpServer;
                oFields.Update();

                Msg.BodyPart.Charset 
= "gb2312";
                Msg.HTMLBodyPart.Charset 
= "gb2312";


                Msg.Send();
                Msg 
= null;
            
            
        }

两种方式的成功率差距很大,后者很高
posted on 2005-07-06 17:03  Gweber.NET  阅读(542)  评论(0编辑  收藏  举报