简体   繁体   English

CDO-不发送电子邮件

[英]CDO - Not Sending email

Helllo, i am calling ASP page from HTML on click of submit button, and in ASP i want to send Email. Helllo,我点击提交按钮后从HTML调用ASP页面,在ASP中我想发送电子邮件。 So i have writen below code, but neither it is sending mail nor i am getting any Error. 所以我已经写了下面的代码,但是既没有发送邮件也没有收到任何错误。

<%
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
%>

Can anyone please help me on this..? 谁能帮我这个忙..?

This code also includes RegExp to prevent your email form from being used by spammers. 此代码还包含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
%>

The configuration fields have been commented for your convenience. 为了方便起见,对配置字段进行了注释。 If your web host mail server does not require authentication you can omit the last three Configuration fields (authentication, username & password). 如果您的Web主机邮件服务器不需要身份验证,则可以省略最后三个配置字段(身份验证,用户名和密码)。

In this line 'expressionmatch = RegularExpressionObject.Test(Request.Form("E-mail"))' the word "E-mail" is the name of the form field containing the sender's email address. 在这一行中,“ expressionmatch = RegularExpressionObject.Test(Request.Form(“ E-mail”))'单词“ E-mail”是包含发件人电子邮件地址的表单字段的名称。

You are continuing on an error so you wont see an error even if get one. 您正在继续执行错误,因此即使遇到错误也不会看到错误。

Remove 去掉

On Error Resume Next

from your code and see what error message you get. 从您的代码中,查看得到的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM