简体   繁体   English

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

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

I grabbed this example from w3school, however when I add an if statement to check if the email has been sent, it displays the false code even though I receive the email. 我从w3school抓取了这个示例,但是,当我添加一条if语句来检查电子邮件是否已发送时,即使我收到了电子邮件,它也会显示错误代码。

Im not sure how asp works, but I'm assuming myMail returns a boolean? 我不确定asp的工作方式,但我假设myMail返回布尔值? Or does it not? 还是不是? How do I check if the email has been sent. 如何检查电子邮件是否已发送。

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

The .Send method just simply sends the message without returning a response. .Send 方法仅发送消息而不返回响应。

You can handle an error raised by a failure to send the message something like the code below: 您可以处理由于无法发送消息而引发的错误,例如以下代码:

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