Archive for the 'asp classic' Category

Old School ASP error trap + ASP CDO email with authentication

April 04th, 2007 | Category: Uncategorized, asp classic

Wow is this old and dusty

Here is the Whole deal:

You pass in the name, email, subject & body

action=test — will alow you too switch to an alernate test config for debuging

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
'Option Explicit
On Error Resume Next
 
	Dim strName, strFrom, strSubject, strBody, strAction, SMTPServer, SMTPUser, SMTPpass, mailTo 
 
		strName = ""
		strFrom = ""
		strSubject = "" 
		strBody = "" 
		strAction = ""	
 
	strAction = trim(Request.Querystring("action"))
	strName = trim(Request.Querystring("name"))
	strFrom = trim(Request.Querystring("emailfrom"))
	'strTo = trim(Request.Querystring("emailto"))
	strSubject = trim(Request.Querystring("emailsubject"))
	strBody = trim(Request.Querystring("emailbody"))
 
 
 
if instr(1, strFrom , "@", 1) < 1 or instr(1, strFrom, ".", 1) < 1 or strName = ""   then
 
	'Do some validation error response - dont send email
	'errormessage = "<font color='ff0000' size='3'>Please fill out your name and email address!</font><br><br>"
	Response.Write = "not_valid"
 
else
 
 
	Set cdoConfig = CreateObject("CDO.Configuration")  
 
 
	Const cdoSendUsingPickup = 1 
	Const cdoSendUsingPort = 2 
	Const cdoAnonymous = 0
	' Use basic (clear-text) authentication. 
	Const cdoBasic = 1
	' Use NTLM authentication 
	Const cdoNTLM = 2 'NTLM
 
 
	if strAction = "test" then
 
' test user
 
	 SMTPServer = "mail.yourserver.com" 
	 SMTPUser = "webform@yourserver.com"
	 SMTPpass = "password"
	 mailTo = "user@yourserver.com"
 
 
	else
 
 
	 SMTPServer = "mail.yourserver.com" 
	 SMTPUser = "webform@yourserver.com"
	 SMTPpass = "password"
	 mailTo = "user@yourserver.com"
 
 
	end if
 
 
    With cdoConfig.Fields  
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing")  = cdoSendUsingPickup
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer 
		.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
		.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPUser
		.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPpass
		.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
		.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update  
    End With  
 
 
 
    Set cdoMessage = CreateObject("CDO.Message")  
 
    With cdoMessage  
        Set .Configuration = cdoConfig  
        .From = SMTPUser 'request.form("youremail")
        .To = mailTo  
        .Subject = "CONTACT YOURDOMAIN.COM" 
 
					message = "Below is the result of your Contact us form, It was submitted on " & formatdatetime(now(),vbLongDate) & " " & vbCrLf & vbCrLf
					message = message & "Name: " & strName & " " & vbCrLf
					message = message & "Email: " & strFrom & " " & vbCrLf
					message = message & "Subject: " & strSubject & " " & vbCrLf
					message = message & "Message: " & strBody & " " & vbCrLf
 
					message = message + "___________________________________________________________" & vbCrLf & vbCrLf
					message = message + "IP Address : " & Request.ServerVariables("Remote_Addr") & vbCrLf
					message = message + "End"
 
 
        .TextBody = message  
        .Send 
    End With 
 
 
 
    Set cdoMessage = Nothing  
    Set cdoConfig = Nothing  
 
 
end if
 
 
 
If err.Number <> 0 Then
  Response.Write "ID = " & "1" & "<p>"
  Response.Write "Number = " & err.Number & "<p>"
  Response.Write "Description = " & err.Description & "<p>"
  Response.Write "Source = " & err.Source
  Response.Write "<BR>"
  err.Clear
else 
 
Response.Write = "OK"
 
End If
No comments