CDO - 即使发送电子邮件,发送电子邮件也会返回false

时间:2012-02-16 23:04:16

标签: asp-classic cdo.message

我从w3school那里抓住了这个例子,但是当我添加一个if语句来检查电子邮件是否已经发送时,即使我收到了电子邮件,也会显示错误的代码。

我不确定asp是如何工作的,但我假设myMail返回一个布尔值?或者不是吗?如何检查电子邮件是否已发送。

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="examplek@exm.com"
myMail.HTMLBody = "<h1>This is a message.</h1>"
If myMail.Send Then
    Response.AddHeader "Content-type", "application/json"
    Response.Write "{ request: 'success'}"
Else
    Response.AddHeader "Content-type", "application/json"
    Response.Write "{ request: 'failed'}"
End If

set myMail=nothing
%>

1 个答案:

答案 0 :(得分:1)

。发送method只是简单地发送消息而不返回响应。

您可以处理因发送消息而导致的错误,如下面的代码:

On Error Resume Next
myMail.Send
If Err.Number = 0 then
    Response.ContentType="application/json"
    Response.Write "{ request: 'success'}"
Else
    Response.ContentType="application/json"
    Response.Write "{ request: 'failed'}"
End If