2013-09-27 4 views
2

Helllo, 제출 단추를 클릭하면 HTML에서 ASP 페이지를 호출하고 ASP에서 전자 메일을 보내려고합니다. 그래서 아래 코드를 작성했지만 메일도 보내지도 않고 오류가 발생하지도 않습니다.CDO - 전자 메일을 보내지 않음

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

아무도 도와 줄 수 없나요?

+0

유효한 이메일 주소를 사용하여 메일을 보내십니까? – Paul

답변

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"))'단어 "전자 메일"은 보낸 사람의 전자 메일 주소가 들어있는 양식 필드의 이름입니다.

0

오류가 계속 발생하므로 오류가 발생하더라도 오류가 표시되지 않습니다.

제거

On Error Resume Next 
코드에서

당신이 무엇을 얻을 오류 메시지를 참조하십시오.

관련 문제