2

你好,我在点击提交按钮时从 HTML 调用 ASP 页面,在 ASP 中我想发送电子邮件。所以我写了下面的代码,但它既没有发送邮件,也没有收到任何错误。

<%
dim myMail
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="FromEmail"
myMail.To="ToEmail"

myMail.HTMLBody = "<h1>This is a message.</h1>"
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

set myMail=nothing
%>

谁能帮我解决这个问题..?

4

2 回答 2

0

此代码还包括 RegExp,以防止垃圾邮件发送者使用您的电子邮件表单。

<%
strVisitorMSG= _
"Your message goes here" & _
"If it's a long message you can break it up using & _" & _
"The last line of your meassage omits & _"

Set RegularExpressionObject = New RegExp
With RegularExpressionObject
.Pattern = "^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
.IgnoreCase = True
.Global = True
End With
expressionmatch = RegularExpressionObject.Test(Request.Form("E-mail"))

If expressionmatch  Then

Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 '1 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Your.smtpServer.name" ' this is your smtp server usually something like smtp.somedomain.com
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 '25 is the standard smtp port but check with your host to be sure
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0 'Can be 0 for No Authentication, 1 for basic authentication or 2 for NTLM (check with your host)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Username" 'The username log in credentials for the email account sending this email, not needed if authentication is set to 0
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "emailPassword" 'The password log in credentials for the email account sending this email, not needed if authentication is set to 0

ObjSendMail.Configuration.Fields.Update

ObjSendMail.From = "FromEmail"
ObjSendMail.To = "ToEmail"
ObjSendMail.Subject = "Place your subject here"

ObjSendMail.TextBody = strVisitorMSG 'uncomment to send plain text email
'ObjSendMail.HTMLBody = strVisitorMSG 'uncomment to send html formatted email

ObjSendMail.Send

Set ObjSendMail = Nothing

End If
Set RegularExpressionObject = nothing
%>

为方便起见,已对配置字段进行了注释。如果您的网络主机邮件服务器不需要身份验证,您可以省略最后三个配置字段(身份验证、用户名和密码)。

在这行 'expressionmatch = RegularExpressionObject.Test(Request.Form("E-mail"))' 中,单词“E-mail”是包含发件人电子邮件地址的表单字段的名称。

于 2013-09-28T10:09:19.517 回答
0

您将继续处理错误,因此即使遇到错误也不会看到错误。

消除

On Error Resume Next

从您的代码中查看您收到的错误消息。

于 2013-09-30T07:51:03.867 回答