簡體   English   中英

CDO-不發送電子郵件

[英]CDO - Not Sending email

Helllo,我點擊提交按鈕后從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
%>

誰能幫我這個忙..?

此代碼還包含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
%>

為了方便起見,對配置字段進行了注釋。 如果您的Web主機郵件服務器不需要身份驗證,則可以省略最后三個配置字段(身份驗證,用戶名和密碼)。

在這一行中,“ expressionmatch = RegularExpressionObject.Test(Request.Form(“ E-mail”))'單詞“ E-mail”是包含發件人電子郵件地址的表單字段的名稱。

您正在繼續執行錯誤,因此即使遇到錯誤也不會看到錯誤。

去掉

On Error Resume Next

從您的代碼中,查看得到的錯誤消息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM