如何检查 myMail.Send 是 true/false

发布于 2024-12-09 02:04:31 字数 3264 浏览 0 评论 0原文

    <%
Dim sent
Dim YourName
Dim YourEmail
Dim YourMessage
Set myMail2=CreateObject("CDO.Message")
YourName = Trim(Request.Form("Name")) 
YourEmail = Trim(Request.Form("Email")) 
YourMessage = Trim(Request.Form("Message")) 

Dim Body
Dim body2
Body = Body & "Their Name: " & VbCrLf & YourName & VbCrLf & VbCrLf
Body = Body & "Their Email: " & VbCrLf & YourEmail & VbCrLf & VbCrLf
Body = Body & "Their Message: " & VbCrLf & YourMessage & VbCrLf & VbCrLf

Set myMail=CreateObject("CDO.Message")
myMail.Subject="A New Enquiry!"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.TextBody=Body
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.1and1.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing



body2="Thank you for contacting us!" & VbCrLf & "This is just a brief message to let you know your form was submitted successfully!"& VbCrLf & VbCrLf & "You may reply to this address, but you may not necessarily receive a reply, "& "you should receive a reply in 1-2 business day(s)!"& VbCrLf & "Thank you very much,"& VbCrLf & VbCrLf & "Musical Matters."& VbCrLf & "[email protected]"

Set myMail2=CreateObject("CDO.Message")
myMail2.Subject="Thanks for Contacting Us!"
myMail2.From="[email protected]"
myMail2.To=YourEmail
myMail2.TextBody=body2 

myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.1and1.com"
'Server port
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail2.Configuration.Fields.Update
myMail2.Send

If myMail2.Send="" Then 
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
set myMail2=nothing

Else
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
set myMail2=nothing
End If

我的 asp 脚本的问题是我需要检查电子邮件是否已发送,并根据结果将它们重定向到错误或成功页面。

    If myMail2.Send="" Then 
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
set myMail2=nothing

Else
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
set myMail2=nothing
End If

在上面的代码中 mymail2.Send="" 因为我正在测试一些东西,我知道我必须将值更改为 true 或 false,请匆忙回答!

提前致谢!

    <%
Dim sent
Dim YourName
Dim YourEmail
Dim YourMessage
Set myMail2=CreateObject("CDO.Message")
YourName = Trim(Request.Form("Name")) 
YourEmail = Trim(Request.Form("Email")) 
YourMessage = Trim(Request.Form("Message")) 

Dim Body
Dim body2
Body = Body & "Their Name: " & VbCrLf & YourName & VbCrLf & VbCrLf
Body = Body & "Their Email: " & VbCrLf & YourEmail & VbCrLf & VbCrLf
Body = Body & "Their Message: " & VbCrLf & YourMessage & VbCrLf & VbCrLf

Set myMail=CreateObject("CDO.Message")
myMail.Subject="A New Enquiry!"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.TextBody=Body
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.1and1.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing



body2="Thank you for contacting us!" & VbCrLf & "This is just a brief message to let you know your form was submitted successfully!"& VbCrLf & VbCrLf & "You may reply to this address, but you may not necessarily receive a reply, "& "you should receive a reply in 1-2 business day(s)!"& VbCrLf & "Thank you very much,"& VbCrLf & VbCrLf & "Musical Matters."& VbCrLf & "[email protected]"

Set myMail2=CreateObject("CDO.Message")
myMail2.Subject="Thanks for Contacting Us!"
myMail2.From="[email protected]"
myMail2.To=YourEmail
myMail2.TextBody=body2 

myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.1and1.com"
'Server port
myMail2.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail2.Configuration.Fields.Update
myMail2.Send

If myMail2.Send="" Then 
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
set myMail2=nothing

Else
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
set myMail2=nothing
End If

The problem with my asp script is that I need to check whether the emails were sent or not and redirect them to an error or success page depending on the result.

    If myMail2.Send="" Then 
Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
set myMail2=nothing

Else
Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
set myMail2=nothing
End If

in the code above mymail2.Send="" because i was testing something, i know i have to change the value to true or false, please be hasty with your answers!

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画尸师 2024-12-16 02:04:31

如果电子邮件地址具有有效的语法并且 SMTP 服务器已启动并运行,则 Send 方法永远不会抛出错误,即使电子邮件地址不存在也是如此。

没有办法 100% 知道电子邮件是否到达目的地 - 我能想到的一件事是检查(使用 FSO)SMTP 根目录中的 BadMailQueue 文件夹发送几秒钟后,如果它们包含新条目,则意味着出现问题。

但是,当您使用外部邮件服务时,您必须联系他们并寻求一种在投递失败时以某种方式收到通知的方法。

If the email address has valid syntax and the SMTP server is up and running, the Send method will never throw error, even if the email address does not exist.

There is no way to know 100% if the email reached its destination - one thing I can think is to check (using FSO) the BadMail and Queue folders in the SMTP root after few seconds from sending, and if they contain new entry it means something went wrong.

However as you're using external mail service, you'll have to contact them and ask for a way to get notified somehow when the delivery fails.

影子的影子 2024-12-16 02:04:31

似乎需要使用 On Error 语句。

On Error Resume Next
myMail2.Send
If Err.Number = 0 Then
    set myMail2 = Nothing
    Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
Else
    set myMail2 = Nothing
    Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
End If

Seems to require using On Error statement.

On Error Resume Next
myMail2.Send
If Err.Number = 0 Then
    set myMail2 = Nothing
    Response.Redirect("http://www.musicalmatters.co.uk/success.htm")
Else
    set myMail2 = Nothing
    Response.Redirect("http://www.musicalmatters.co.uk/error.htm")
End If
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文