我很早之前的Blog,说过可能导致 could not access 'cdo.message' object 异常的几种情况。今天新有发现几种情况下,会报这个错误,特整理,导致这个异常的情况:
1、没有权限:
具体看:
http://blog.joycode.com/ghj/archive/2004/02/17/13197.aspx
2、System.Web.Mail FAQ 这里提供了另外6种情况,我就不转贴了,自己查
http://www.systemwebmail.com/faq/4.2.3.aspx
3、你装了杀毒软件,或者防火墙,
以McAfee VirusScan Enterprise 8.0 为例,在端口限制中,默认限制了除 amgrsrvc.exe,tomcat.exe,outlook.exe,msimn.exe,agent.exe,eudora.exe,nlnotes.exe,mozilla.exe,netscp.exe,
opera.exe,pine.exe,poco.exe,thebat.exe,thunderbird.exe,ntaskldr.exe,inetinfo.exe,nsmtp.exe,nrouter.exe,
tomcat5.exe,tomcat5w.exe,ebs.exe,FireSvc.exe,modulewrapper.exe,MSKSrvr.exe,MSKDetct.exe 这些程序外对 25 端口的请求。 而25端口是SMTP 用的。这时候就会报 未能访问“CDO.Message”对象 对象错误;只要把你的程序名放到例外名单中,即可绕过这个限制。如下图:
4、你的Mail服务器性能不太好,经常超时,或其他错误,也会报:未能访问“CDO.Message”对象 的错误。
打印 | 张贴于 2004-10-22 13:23:00 | Tag:.net 编程心得 网站开发管理相关内容
留言反馈
{
Response.Write(ero.Message);
}
这样出错的捕获到的都是未能访问“CDO.Message”对象。
如果你直接捕获Exception 就行看到详细信息了,不知是不是一个BUG,如果是没验证成功成就会提示没验证成功,网络问题或杀毒软件问题会提示无法连接服务器的
I have no idea why this suggestion works, but I found it on the web. I figured I would mention it, just in case Suggestion 1 did not work. Instead of specifying
SmtpMail.SmtpServer = "127.0.0.1"
try
SmtpMail.SmtpServer.Insert( 0, "127.0.0.1 or your mail server name here")
我各种解决方案都试过了,没用。
按照这个试了一下,通过!倒。
我已经试着关闭了我计算机上的杀毒软件和防火墙,还是一样出错
But Now, I use your suggestion, then I slove my problem finally. It can work again!! When I see I can send a mail successfully, I can't beleive it! How wonderful you are. I always appreciate your kindess from the far side on the Internet.
未处理的“System.Web.HttpException”类型的异常出现在 system.web.dll 中。
其他信息: Could not access 'CDO.Message' object.
是什么原因呢?
帮我解决一下我的问题:
开始时是未能访问“CDO.Message”对象
调试过后说:At least one recipient is required, but none were found.
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Runtime.InteropServices.COMException: At least one recipient is required, but none were found.
敬请回复:wangwen977@sohu.com 谢谢!
程序如下:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Mail" %>
<html>
<head><title>电子贺卡</title></head>
<body background="../B01.jpg" bgcolor="#FFFFFF">
<h2>电子贺卡 -- <font size="3">最省钱、最快速的问候</font><hr></h2>
<Form runat="server">
<table border="0">
<tr>
<td>收卡人:</td>
<td>
<asp:TextBox runat="server" size="10" id="ToName" />
<asp:RequiredFieldValidator runat="server" Text="(必要栏位)"
ControlToValidate="ToName" EnableClientScript="False"
Display="Dynamic" />
信箱:<asp:TextBox runat="server" size="40" id="ToEmail" />
<asp:RequiredFieldValidator runat="server" Text="(必要栏位)"
ControlToValidate="ToEmail" EnableClientScript="False"
Display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
ControlToValidate="ToEmail" Text="(Email 应含有 @ 符号)"
ValidationExpression=".{1,}@.{3,}"
EnableClientScript="False" Display="Dynamic"/>
</td></tr>
<tr><td>寄卡人:</td>
<td>
<asp:TextBox runat="server" size="10" id="FromName"/>
<asp:RequiredFieldValidator runat="server" Text="(必要栏位)"
ControlToValidate="FromName" EnableClientScript="False"
Display="Dynamic" />
信箱:<asp:TextBox runat="server" size="40" id="FromEmail"/>
<asp:RequiredFieldValidator runat="server" Text="(必要栏位)"
ControlToValidate="FromEmail" EnableClientScript="False"
Display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
ControlToValidate="FromEmail" Text="(Email 应含有 @ 符号)"
ValidationExpression=".{1,}@.{3,}"
EnableClientScript="False" Display="Dynamic"/>
</td></tr>
<tr><td valign="top">留 言:</td>
<td valign="top">
<asp:TextBox runat="server" id= "Body" TextMode="Multiline"
rows="8" cols="60"/>
<asp:RequiredFieldValidator runat="server" Text="(必要栏位)"
ControlToValidate="Body" EnableClientScript="False"
Display="Dynamic" />
</td></tr>
<tr><td valign="top">卡 片:</td>
<td valign="top">
<asp:RadioButtonList runat="server" id="Card"
RepeatDirection="Horizontal" RepeatColumns="4">
<asp:ListItem Selected><Img src="scard15.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard16.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard17.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard18.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard14.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard20.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard21.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard22.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard23.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard24.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard25.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard26.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard27.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard28.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard29.gif" align="middle">
</asp:ListItem>
<asp:ListItem><Img src="scard31.gif" align="middle">
</asp:ListItem>
</asp:RadioButtonList>
</td></tr>
</table>
<asp:Button runat="server" Text="送出贺卡" OnClick="SendCard_Click" />
<asp:Button runat="server" Text="先检视卡片" OnClick="ViewCard_Click"/>
<p>
<asp:Label runat="server" id="Msg" ForeColor="Red" />
</Form>
<hr>
</body>
</html>
<script Language="VB" runat="server">
Sub SendCard_Click(sender As Object, e As EventArgs)
Msg.Text = ""
If IsValid Then
WriteDataToDatabase()
SendCard()
' 清除「收件人」及「留言」栏位,但保留「寄件人」栏位
ToEmail.Text = ""
ToName.Text = ""
Body.Text = ""
End If
Dim mail As MailMessage = New MailMessage
mail.To = ToEmail.Text
mail.From = FromEmail.Text
mail.Subject = "来自 " & FromName.Text & " 的卡片"
mail.BodyFormat = MailFormat.Text
mail.Body = Body.text
Smtpmail.SmtpServer = "61.135.132.99"
Smtpmail.Send(Mail)
End Sub
Sub ViewCard_Click(sender As Object, e As EventArgs)
Response.Redirect( "ViewCard.aspx?Card=" & Card.SelectedItem.Text )
End Sub
Sub SendCard()
' 产生 EcardGet.aspx 的完整网址
Dim ServerName = Request.ServerVariables("SERVER_NAME")
Dim Path = Request.ServerVariables("PATH_INFO")
Dim URL = "http://" & ServerName & Path
URL = Replace( URL, "Ecard", "EcardGet",,,CompareMethod.Text )
' 读取 Ecard.txt 档案内容
Dim File As String = Server.MapPath("Ecard.txt")
Dim sReader As StreamReader
sReader = New StreamReader( File, Encoding.Default )
Dim Body As String = sReader.ReadToEnd()
sReader.Close()
' 将 Ecard.txt 中的未定资料取代成真实资料
Body = Replace( Body, "=ToName=", ToName.Text )
Body = Replace( Body, "=FromName=", FromName.Text )
Body = Replace( Body, "=From=", FromEmail.Text )
Body = Replace( Body, "=To=", ToEmail.Text )
Dim EcardID = URL & "?ToEmail=" & ToEmail.Text & _
"&FromEmail=" & FromEmail.Text
Body = Replace( Body, "=EcardID=", EcardID )
Body = Replace( Body, "=Now=", Now )
' 送出贺卡邮件
Dim mail As MailMessage = New MailMessage
mail.To = ToEmail.Text
mail.From = FromEmail.Text
mail.Subject = "来自 " & FromName.Text & " 的卡片"
mail.BodyFormat = MailFormat.Text
mail.Body = Body
On Error Resume Next
SmtpMail.SmtpServer = "61.135.132.99"
SmtpMail.Send(mail)
If Err.Number <> 0 Then
Msg.Text = Err.Description
Else
Msg.Text = "卡片已经送出!"
End If
End Sub
Sub WriteDataToDatabase()
Dim Conn As OleDbConnection
Dim Cmd As OleDbCommand
Dim Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim Database = "Data Source=" & Server.MapPath( "ECard.mdb" )
Conn = New OleDbConnection( Provider & ";" & DataBase )
Conn.Open()
Dim SQL As String
SQL = "INSERT INTO ECard (ToEmail, FromEmail, ToName, FromName, Body, Card) VALUES (?, ?, ?, ?, ?, ?)"
Cmd = New OleDbCommand( SQL, Conn )
Cmd.Parameters.Add( New OleDbParameter("@ToEmail", OleDbType.Char, 255))
Cmd.Parameters.Add( New OleDbParameter("@FromEmail", OleDbType.Char, 255))
Cmd.Parameters.Add( New OleDbParameter("@ToName", OleDbType.Char, 255))
Cmd.Parameters.Add( New OleDbParameter("@FromName", OleDbType.Char, 255))
Cmd.Parameters.Add( New OleDbParameter("@Body", OleDbType.VarChar))
Cmd.Parameters.Add( New OleDbParameter("@Card", OleDbType.Char, 255))
Cmd.Parameters(0).Value = ToEmail.Text
Cmd.Parameters(1).Value = FromEmail.Text
Cmd.Parameters(2).Value = ToName.Text
Cmd.Parameters(3).Value = FromName.Text
Cmd.Parameters(4).Value = Body.Text
Cmd.Parameters(5).Value = Replace(Card.SelectedItem.Text, "scard", "card")
Cmd.ExecuteNonQuery()
Conn.Close()
End Sub
</script>
请问该怎么分析这个问题
敬请l回复:yaolei1@mindray.com.cn
我这次就栽到这里了,我以为只有装了防火墙才可能会有这种情况,谁知到,McAfee 的杀毒软件,增加了:通过限制程序访问25端口的方式,来限制一些蠕虫病毒。由于导致这个错误 未能访问“CDO.Message”对象 的情况太多了,之前一直在其他方面找原因,谁知是杀毒软件的问题。