我的代码如下:结果虽然显示success,但邮箱力里却没有邮件,不知道为何???
//发送邮件:
MailMessage mailMess=new MailMessage();
mailMess.To="[email protected]";
mailMess.From="[email protected]";
for(int i=0;i<2;i++)
{
     try
     {
mailMess.Subject="你好帅哦 mail测试"+i*10;
mailMess.BodyFormat=MailFormat.Text;
mailMess.Body="希望你越来越帅\n这是一个含有附件的Email";
mailMess.Attachments.Add(new MailAttachment(Server.MapPath("mytext.txt")));
SmtpMail.Send(mailMess);
         Response.Write("success!\n");
     }
     catch(Exception ex)
     {
Response.Write(ex.Message+"\n");
     }

解决方案 »

  1.   

    SmtpMail.SmtpServer = "your SmtpMail server";
      

  2.   

    System.Web.Mail.SmtpMail.SmtpServer="smtp.163.com"; 
    //验证 
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
    //登陆名 
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "yourUserName"); 
    //登陆密码 
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "yourPassword"); //发送 
    System.Web.Mail.SmtpMail.Send(mail);参考:http://blog.csdn.net/sykpboy/archive/2005/04/06/338710.aspx
      

  3.   

    楼上的我将照你所说代码改为如下:但是出现“未能访问“CDO.Message”对象。”错误。
    mailMess.Subject="你好帅哦 mail测试"+i*10;
    mailMess.BodyFormat=MailFormat.Text;
    mailMess.Body="希望你越来越帅\n这是一个含有附件的Email";
    mailMess.Attachments.Add(new MailAttachment(Server.MapPath("mytext.txt")));
    SmtpMail.SmtpServer="smtp.163.com"; 
    //验证 
    mailMess.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
    //登陆名 
    mailMess.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","peter3797"); 
    //登陆密码 
    mailMess.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","×××××"); 
    //发送 
    SmtpMail.Send(mailMess); Response.Write("success!\n");
      

  4.   

    那你看下你们邮件服务器的防火墙的问题,我们公司之前也是由于邮件防火墙的问题所以没有能够实现,不过现在解决咯.开启邮件服务器的ASP.NET账号权限
      

  5.   

    et jmail=server.CreateObject("JMAIL.Message")
    jmail.Logging = true
    jmail.From="[email protected]"
    jmail.ReplyTo="[email protected]"
    jmail.AddRecipient "[email protected]"
    jmail.Subject="新用户注册!"
    jmail.Body="用户注册信息"
    jmail.MailServerUserName="brookes"
    jmail.MailServerPassword="pass"
    jmail.Send( "mail.server.com" )
    jmail.Close
    set jmail=nothingw3Jmail4 Jmail.Message参考:
    (1)Body(信件正文) : 字符串 
    如:Jmail.Body = "这里可以是用户填写的表单内容,可以取自From。" 
    (2)Charset(字符集,缺省为"US-ASCII") : 字符串 
    如:Jmail.Charset = "US-ASCII" 
    (3)ContentTransferEncoding : 字符串 
    指定内容传送时的编码方式,缺省是"Quoted-Printable" 
    如:Jmail.ContentTransferEncoding = "base64" 
    (4)ContentType(信件的contentype. 缺省是"text/plain") : 字符串
    如果你以HTML格式发送邮件, 改为"text/html"即可。 
    如:Jmail.ContentType = "text/html" 
    (5)Encoding : 字符串 
    设置附件编码方式(缺省是"base64)。 可以选择使用的是"base64", "uuencode" or "quoted-printable" 
    如:Jmail.Encoding = "base64" 
    (6)Log(Jmail创建的日志,前提loging属性设置为true,见下面) : 字符串 
    如:使用Response.Write( Jmail.Log )语句列出日志信息。 
    (7)Logging(是否使用日志) : 布尔型 
    如:Jmail.Logging = true 
    (8)Recipients : 字符串 
    只读属性,返回所有收件人 
    如:Response.Write( "" + Jmail.Recipients + "" ); 
    (9)ReplyTo(指定别的回信地址) : 字符串 
    如:Jmail.ReplyTo = "[email protected]
    (10)Sender( 发件人的邮件地址) : 字符串 
    如:Jmail.Sender = "[email protected]
    (11)SenderName(发件人的姓名) : 字符串 
    如:Jmail.SenderName = "一克" 
    (12)ServerAddress(邮件服务器的地址) : 字符串 
    你可以指定多个服务器,用分号点开。可以指定端口号。 
    如果serverAddress保持空白,Jmail会尝试远程邮件服务器,然后直接发送到服务器上去。 
    如:Jmail.ServerAddress = "mail.263.net.cn" 
    (13)Subject(设定邮件的标题,可以取自From。):字符串 
    如:Jmail.Subject = "客户反馈表单" 
    (14)添加文件附件到邮件 
    如:Jmail.AddAttachment( "c:\anyfile.zip" ) 
    (15)AddCustomAttachment( FileName, Data ) 
    添加自定义附件. 
    如:Jmail.AddCustomAttachment( "anyfile.txt", "Contents of file" ); 
    (16)AddHeader( Header, Value ) 
    添加用户定义的信件标头。 
    如:Jmail.AddHeader( "Originating-IP","192.168.10.10" ); 
    (17)AddRecipient(收件人):字符串 
    如:Jmail.AddRecipient( "[email protected]" ); 
    (18)AddRecipientBCC( Email ),密件收件人: 
    如:Jmail.AddRecipientBCC( "[email protected]" ); 
    (19)AddRecipientCC( Email ) ,抄送收件人: 
    如:Jmail.AddRecipientCC( "[email protected]" ) 
    (20)AddURLAttachment( URL, 文档名) 
    下载并添加一个来自url的附件. 第二个参数"文档名", 用来指定信件收到后的文件名。 
    如:Jmail.AddURLAttachment( "http://www.chinabs.net/jmail.zip", "jmail" ) 
    (21)AppendBodyFromFile( 文件名) ,将文件作为信件正文: 
    如:Jmail.AppendBodyFromFile( "c:\anyfile.txt" ) 
    (22)AppendText( Text ) 
    追加信件的正文内容,比如增加问候语或者其它信息。 
    如:Jmail.AppendText( "欢迎访问本站!" ) 
    (23)Close() ,强制Jmail关闭缓冲的与邮件服务器的连接: 
    如:Jmail.Close() 
    (24)Execute() ,执行邮件的发送 
    如:Jmail.Execute()1.一定要给定jmail.MailServerUserName jmail.MailServerPassword,用于邮件服务器验证
    2.去掉on error resume next调试,捕获错误信息。
      

  6.   

    如果你在局域网内部,可能是防火墙问题.对于未能访问“CDO.Message”对象这个错误,你可以在google搜索一下,常见问题,原因比较多.