簡體   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