FancyPrairie
Programmer
I've created several data access pages that run client side. However, I need to email users. I can't email client side because my users are using didn't version of Windows (95,98,XP,2000) and different versions of Office. Consequently, some have CDONTS installed and other CDO and some neither. Therefore, I need to send the email via the server. I used Remote Scripting to do this (which worked great). But now our IT dept is installing the runtime version of Sun's Java. This causes a proble with remote scripting. So I discovered XMLHttp. The following code works, but the asp page strips out all of the spaces in the data sent to it.
How do I code it to so that the asp page reads the data as sent (spaces intact)?
Client Side Code
Server Side
How do I code it to so that the asp page reads the data as sent (spaces intact)?
Client Side Code
Code:
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title> Email Test</title>
<script language="VBScript" >
'*************************
'* Setup email to send *
'*************************
Function SetupEmail()
MMC_Startup "Live",""
msgbox "here i am"
strFrom = "MyEmailAddress"
strTo = "MyEmailAddress"
strCC = vbnullstring
strBC = vbnullstring
strSubject = "Subject"
strBody = "This is a test"
strAttachFile = vbnullstring
strBodyFormat = vbnullstring
strMailFormat = vbnullstring
strEmailValue = "From=" & strFrom & "&To=" & strTo & "&Subject=" & strSubject & "&Body=" & strBody
msgbox PostEmail( strEmailValue)
End Function
'*************************************
'* Post email via send to asp page *
'*************************************
Function PostEmail(ByVal strEmailValues)
Dim sLink, xmlHttp
sLink = "[URL unfurl="true"]http://mypath/SendEmail.asp"[/URL]
set xmlHttp = CreateObject("Msxml2.XMLHTTP.4.0")
xmlHttp.open "POST", sLink, false
xmlHttp.setRequestHeader "Content-Type", "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
msgbox stremailvalues
xmlHttp.send strEmailValues
PostEmail = xmlHttp.responseText
End Function
</script>
</head>
<body>
<h1>Email Test</h1>
<p><input type="button" value="Click here to send email" onclick="SetupEmail()"/></p>
</body>
</html>
Server Side
Code:
<%@language=VBScript%>
<%
'********************************
'* Declaration Specifications *
'********************************
Dim lngBodyFormat 'Body Format (0 or 1, default 1)
Dim lngMailFormat 'Mail Format (0 or 1, default 1)
Dim lngImportance 'Importance (0=low; 1=medium; 2=highest)
Dim strError 'String Returned to caller (Success or Error and error message)
Dim strFrom 'Indicates From whom the message was sent
Dim strTo 'Indicates To whom the message is to be sent
Dim strCc 'Courtesy copy
Dim strBcc 'Blind Courtesy copy
Dim strSubject 'Subject of email
Dim strBody 'Body of Email
Dim strAttachFile 'Source, Filename, Encoding Method
Dim strContentBase 'Content Base
Dim strCurrentLocation 'Current Location
Dim strValue 'Value
Dim strAttachURL 'Attached URL
Dim strSetLocaleIDs 'Local Ids
Dim objEMail 'Email Object
strError = vbNullString
'************************************************
'* Extract the value for each argument passed *
'************************************************
strFrom = Request("From")
if (len(strFrom) = 0) then strError = "Missing FROM property"
strTo = Request("To")
if (len(strTo) = 0) then strError = strError & vbCrLf & "Missing TO property"
strCc = Request("Cc")
strBcc = Request("Bcc")
lngBodyFormat = Request("BodyFormat")
if (len(lngBodyFormat) > 0) then
if (lngBodyFormat <> 0) and (lngBodyFormat <> 1) then lngBodyFormat = 1
else
lngBodyformat = 1
end if
lngMailFormat = Request("MailFormat")
if (len(lngMailFormat) > 0) then
if (lngMailFormat <> 0) and (lngMailFormat <> 1) then lngMailFormat = 1
else
lngMailFormat = 1
end if
lngImportance = Request("Importance")
if (len(lngImportance) > 0) then
if (lngImportance < 0) or (lngImportance > 2) then lngImportance = 1
else
lngImportance = 1
end if
strSubject = Request("Subject")
strBody = Request("Body")
strContentBase = Request("ContentBase")
strCurrentLocation = Request("CurrentLocation")
strValue = Request("Value")
strAttachFile = Request("AttachFile")
strAttachURL = Request("AttachURL")
strSetLocaleIDs = Request("SetLocaleIDs")
response.write Server.URLEncode(strBody)
'*******************************************************************************************
'* If From and To properties contain values, then set the properties of the email object *
'* and send the email. *
'*******************************************************************************************
if (len(strFrom) > 0) and (len(strTo) > 0) then
on error resume next
Set objEMail = Server.CreateObject("CDONTS.NewMail")
objEmail.From = strFrom
objEMail.To = strTo
if (len(strCc) > 0) then objEMail.Cc = strCc
if (len(strBcc) > 0) then objEMail.Bcc = strBcc
if (len(strSubject) > 0) then objEMail.Subject = strSubject
if (len(strBody) > 0) then objEMail.Body = strBody
if (len(strContentBase) > 0) then objEmail.ContentBase = strContentBase
if (len(strCurrentLocation) > 0) then objEmail.CurrentLocation = strCurrentLocation
if (len(strValue) > 0) then objEmail.Value = strValue
response.write strBody
objEMail.BodyFormat = lngBodyFormat
objEMail.MailFormat = lngMailFormat
objEMail.Importance = lngImportance
if (len(strAttachFile) > 0) then objEMail.Attachfile strAttachFile
if (len(strAttachURL) > 0) then objEmail.AttachURL strAttachURL
if (len(strSetLocaleIDs) > 0) then objEmail.SetLocaleIDs strSetLocaleIDs
objEMail.Send
response.write err.number & err.description
Set objEMail = Nothing
Response.Write "Success"
else
Response.Write "Error" & vbcrlf & strError
end if
%>