classic asp send mail - asp-classic

I am using this code to send email using classic ASP:
Set oJMail = Server.CreateObject("JMail.SMTPMail")
with oJMail
.Sender = "myemail"
.SenderName = "Me"
.AddRecipient "some email"
.Subject = "some subject"
.Body = "Name: " & fname & " Email:" & email & "Phone: " & phone
end with
oJMail.ServerAddress = "mysmtp:25"
oJMail.Execute
Set oJMail = Nothing
But the server keep throwing this error:
Microsoft JScript compilation error '800a03ec'
Expected ';'
/index.asp, line 108
Set oJMail = Server.CreateObject("JMail.SMTPMail")
----^
Can it be something to do with my page header?
<%# Language="javascript" %>

Yes, that looks like VBScript code, in which case you'd want your page header to have:
<%# Language="VBScript" %>
Of course, this causes problems if the rest of your page is already written in JavaScript.

Related

Removal of <% %> and %><% in Classic ASP when there is nothing between them causes the web page to crash. Why is that?

I am working with Classic ASP and I have a need to make the code simpler. In an effort to do what is similar to what we see here: Auto-populating Select Field via jQuery's Ajax where we use ajax to populate a select filed, we load the contents of a area with by using a separate asp file to load. I assume that the loaded file is free of <% markings. While testing the commands contained in that file I am in the process of removing those marks. Why would removing a %><% mark (where it is just a close followed by an open) throw an error? And why would it be necessary to have something like %>"<% where it is just one character?
The reason why I posted an image of the code block was because the %> and %> symbols were highlighted by color in such a way as to better visualize what was going on.
Here is the code block:
<%
Function FunctionName(name, selection)
%>
<select name = "<%= name%>"><%
Set RTConn = Server.CreateObject("ADODB.Connection")
RTConn.Open("Provider=SQLOLEDB;Password=three4me;Persist Security Info=True;User ID=sa;Initial Catalog=DATABASE;Data Source=SERVER")
Set RT = Server.CreateObject("ADODB.Recordset")
sqlQuery = "SELECT DISTINCT id, Replace(Name, ' ', ' ') AS Name, Num, Address, City, State FROM RedactedTablename WHERE active = 1 OR ID = '" & selection & "' ORDER BY Replace(Name, ' ', ' '), State, City, Num"
RT.Open sqlQuery, RTConn, 3, 3
Do While Not RT.EOF
response.write "<option value=" & RT.Fields("id")
%>" <%
if cstr(RT.Fields("id")) = selection then
response.write " selected "
elseif (selection = "" OR selection = "0") AND trim(RT.Fields("Name")) = "NA" then
response.write " selected "
end if
%>><%=RT.Fields("Name")%><%
if not RT.Fields("Name") = "NA" AND not RT.Fields("Name") = "NA" then
response.write " (" & RT.Fields("City") & ", " & RT.Fields("State") & ") - " & RT.Fields("Num")
end if
%>
response.write"</option>"
<%
RT.MoveNext
Loop
RT.Close
RTConn.Close %>
</select>
<%
End function
%>
The end tag that was removed was paired with a start tag of <%= not <% which has caused the syntax error.
The reason is <%= is a shorthand form of Response.Write and has to be paired with a closing %> tag.
Acceptable:
<%= link_label %>
Invalid syntax:
<%= link_label
Also, there are other issues with the code, for example, #Flakes pointed out in the comments that response.write"</option>" is not located within Classic ASP preprocessor tags (<% and %>).
While this won't cause a syntax error it will cause the line to be interpreted as HTML and will be output to the client as is.

Cannot send email from godaddy smtp using classic asp - going mad

I am really struggling with something which is pretty basic and need some help as it was not forthcoming from godaddy support!
For some reason the code below is not sending out any emails.
Code seems to be executed property and riddled it with lots of debug msgs but to no helping!
Te "From" email address is valid and has no issues! Any ideas? Port?
cheers, Jay
<%
Dim objNewMail
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "info#example.com"
objNewMail.To = "info#example.com"
objNewMail.Subject = "Interesting property sent by xxx"
objNewMail.TextBody = "Click the following link to see the property :" '& vbcr & vbcr & "http://www.maltawide.eu/default.asp?pid="
' GoDaddy SMTP Settings
'I had to remove the smpt settings as I dont have enough rep to post two links!
Response.Write ("Message sent successfully!")
%>
I'm not sure why your message failed, but here is code from a working mail form hosted at GoDaddy. All you need to do is build the form page to submit the form fields used in the script, or change the form field names in the script to match your existing form, or replace the forms with strings. Examples of both form entry and assigned variable values are included in the example's ' Create the message part of the code.
<%
Dim strBody
Dim strToAddress
Dim strFromAddress
Dim strReplyAddress
Dim strBlindCC
' Create the message
strBody = Request.Form("Message")
strToAddress = Request.Form("ToAddress")
strFromAddress = Request.Form("FromAddress")
strReplyAddress = "NoReply#WebSite.com"
strBlindCC = "BlindCC#WebSite.com"
' Include the schemas
sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"
' Set the mail server configuration
Set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendUrl)=2 ' cdoSendUsingPort
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
objConfig.Fields.Update
' Send the message
Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration=objConfig
objMail.From=strFromAddress
objMail.ReplyTo=strReplyAddress
objMail.To=strToAddress
objMail.BCC=strBlindCC
objMail.Subject=strSubject
objMail.HTMLBody = strBody
objMail.Send
%>

Error in Classic ASP page while reading rss feed

We have an old application developed in classic ASP and today it is generating an error while consuming RSS feed. After through investigating(tried to wrote code in .NET to get detailed error) found its special character, in generated output which is causing trouble. When you run RSS feed in browser and run generated XML from local server, it works fine.
Error: System error: -2147012866.
Line: 0
Text:
I have no idea how to fix it.
<%
Dim objXML
Dim objItemList
Dim objItem
Dim I
Set objXML = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
objXML.async = False
I = 0
objXML.setProperty "ServerHTTPSRequest", True
'objXML.Load(Server.MapPath("abcd.xml"))
objXML.Load("http://search.jobs.wa.gov.au/wagov.rss?agencyID=925")
If objXML.parseError.errorCode <> 0 Then
Response.Write "<pre>" & vbCrLf
Response.Write "<strong>Error:</strong> " & objXML.parseError.reason
Response.Write "<strong>Line:</strong> " & objXML.parseError.line & vbCrLf
Response.Write "<strong>Text:</strong> " & Server.HTMLEncode(objXML.parseError.srcText) & vbCrLf
Response.Write "</pre>" & vbCrLf
End If
%>
Zam,
Even if you correct it from ServerHTTPSRequest to ServerHTTPRequest in SetProperty, still nothing works.
As mentioned in question, it also worked fine when you use saved the XML file(generated from RSS FEED)
Also, if you look into below post, it states that it's all because of encoding="iso-8859-1" which is also the case for above issue.
http://stackoverflow.com/questions/4332828/vbscript-tries-to-read-rss-feeds-have-issue-of-system-does-not-support-the-speci
but solution provided there causes another error that The connection with the server was terminated abnormally
I believe error in objXML.SetProperty "ServerHTTPSRequest", True
Because
Error description: Property name is invalid.

Formatting classic ASP in an email

Can anyone tell me how i would format the following ASP line for an email with bold
email_body = email_body & "Full Name: " & fullname & vbcrlf & vbcrlf
I also tried:
email_body = email_body & "<b>Full Name:</b> " & fullname & vbcrlf & vbcrlf
But it didn't work, just showed the tags
The email just showed the bold tags
Sorry the format I want is
Full Name: John Smith
And the ASP code is:
email_body = email_body & "Full Name: " & fullname & vbcrlf & vbcrlf <br />
I tried adding the Bold tags around the Full name, but it didn't format it just showed the actual tags
In order to have bold or other text formatting in an email, you have to make sure that the email is sent as HTML and not plain text. In your case it seems to be sent as plain text. Here are the ways to do it with the common mail components (some code copied from respective documentations):
CDO
objMessage.HTMLBody = "<h1>This is some sample message html.</h1>"
(the property is HTMLBody, not simply Body). Source: http://www.paulsadowski.com/wsh/cdo.htm
ASPEmail
Add:
Mail.IsHTML = True
Source: http://www.aspemail.com/manual_02.html
JMail
Add:
JMail.ContentType = "text/html"
Source: http://www.aspwebpro.com/aspscripts/email/jmail.asp
Set Mail = Server.CreateObject("CDONTS.NewMail")
Mail.from = "me#me.com"
Mail.to = "me#me.com"
Mail.subject = "To Me"
sBody = "<h1>blah blah</h1>"
Mail.bodyFormat = CdoBodyFormatHTML
Mail.body = sBody
Mail.send

vbscript not retrieving all server variables

I have a website that was written in VBSCRIPT that I am moving over to VB.NET. Until I have time to get to rewriting some pages/applications, I would like to update some of the code so they work a bit better. I am trying to grab a server variable on the VBSCRIPT page that contains our username from the enterprise login.
I have 2 test pages here, one with language="VB" at the top and the other language="VBSCRIPT".
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Server Variables</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<%
For Each var In Request.ServerVariables
Response.Write("<b>" + var + "</b>= " + Request.ServerVariables(var) + "<br />")
Next
%>
</div>
</form>
</body>
</html>
The VBSCRIPT page will list variables with no data when they have data on the VB page and in ALL_HTTP. Is there any way I can get VBSCRIPT to gather the correct info for all the server variables?
Thank You
EDIT: These are the variables that vary between VB and VBS
AUTH_USER, REMOTE_USER - logged in user on VBS, iis_anon on VB
REMOTE_PORT - not listed in VBS
The following are listed in VBS, but have no data
HTTP_SERVER_PROTOCOL
HTTP_SM_TRANSACTIONID
HTTP_SM_CLIENT_IP
HTTP_REQUEST_METHOD
HTTP_SM_SDOMAIN
HTTP_SM_REALM
HTTP_SM_REALMOID
HTTP_SM_AUTHTYPE
HTTP_SM_AUTHREASON
HTTP_SM_UNIVERSALID
HTTP_SM_AUTHDIROID
HTTP_SM_AUTHDIRNAME
HTTP_SM_AUTHDIRSERVER
HTTP_SM_AUTHDIRNAMESPACE
HTTP_SM_USER
HTTP_SM_USERDN
HTTP_SM_SERVERSESSIONID
HTTP_SM_SERVERSESSIONSPEC
HTTP_SM_TIMETOEXPIRE
HTTP_SM_SERVERIDENTITYSPEC
HTTP_REMOTE_USER
Also there is a custom on I wish to get that is used for our enterprise authentication.
I've had this issue before with custom HTTP headers that have underscores in the raw header name (which can be seen in the ALL_RAW server variable). The HTTP_ converts underscores to dashes (e.g., HTTP_USER_AGENT corresponds to an actual header called User-Agent). In order to retrieve the values of any headers that have underscores in their names, you have to use the HEADER_ prefix, which will search for the exact header name (e.g., HEADER_USER_AGENT will search for a header called User_Agent).
By the way, this blog post offers some more background information on why there are two prefixes.
here a classic ASP page i have running on various IIS versions.
For the user, i have this in most of my projects which makes userinfo available on the server and client side. If you are on a domain replace DMAIN with yours, otherwise you can drop the replace.
NTLM security has to be enabled (windows authentication) on your IIS site, no anonymous access.
The list of servarvariables returned by this code is different depending on OS and IIS versions, enabled features, settings etc. Some keys will have empty values, so eg REMOTE_PORT is not avaiable on mine (i use the standard 80 port) but SERVER_PORT is.
<%
Dim user
user = Replace(uCase(Request.ServerVariables("AUTH_USER")), "DOMAIN\", "")
%>
<script type="text/javascript">var user = <%=user%></script>
Here the contents of servervariables.asp
<html>
<%#language=VBScript%>
<%
With Response
.Expires=-1
.Clear
End With
dim teller
response.write "<h1>Servervariables</h1>"
response.write "<table>"
teller = 1
for each subkey in Request.Servervariables
response.write "<tr><td>"
response.write teller
response.write "</td><td>"
response.write (Request.Servervariables.Key(teller))
response.write "</td><td>"
response.write (Request.Servervariables.Item(teller))
response.write "</td></tr>"
teller = teller + 1
next
response.write "</table>"
response.write request.servervariables("path_translated") & "<br>"
response.write "USER cookie:" & Request.Cookies("USER") & "<br>"
response.write "USER Sessionvariable:" & Session("USER") & "<br>"
%>
</html>

Resources