繁体   English   中英

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

[英]CDO - Sending email returns false even though the email is sent

我从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
%>

.Send 方法仅发送消息而不返回响应。

您可以处理由于无法发送消息而引发的错误,例如以下代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM