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.
Im not sure how asp works, but I'm assuming myMail returns a boolean? 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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.