Forum Moderators: open

Message Too Old, No Replies

ASP - inserting a record AND emailing the form output

         

kosmoraios

8:37 pm on May 27, 2004 (gmt 0)

10+ Year Member



Any help on this will be greatly appreciated. Many karma points will be awarded.

Here's the deal: I have an ASP form inserting records into a FoxPro Database on windows 2k running IIS. I want the form to send email at the same time that it updates the records - this is for an IT Helpdesk request. I tried inserting the CDONTS.NewMail stuff in the script and it dies - expecting end of statement.

"Error Type:
Microsoft JScript compilation (0x800A03EC)
Expected ';'
/request.asp, line 81, column 4"

I put the code in like this after it writes to the table:

MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

Set objMailer = Server.CreateObject("CDONTS.NewMail")
objMailer.From = "IT request"
objMailer.To = "*******@*******.***"
objMailer.Subject = " ******** "
objMailer.BodyFormat = 0

objMailer.MailFormat = 0
objMailer.Importance = 2
objMailer.Body = " **** "
objMailer.Send
Set objMailer = nothing

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

Line 81, column 4 is right in front of the Set objMailer. If there's another way to do this, great! Also, I know that my IT department blocks all outgoing SMTP traffic - It has to go through our mailserver. Is there a way to set that?

Thanks!

duckhunter

2:26 am on May 28, 2004 (gmt 0)

10+ Year Member



Looks like the page language is set to JSCRIPT and you are writing VBSCRIPT.

Make sure the top line of your ASP is:
<%@ LANGUAGE="VBSCRIPT"%>

dotme

12:39 pm on May 28, 2004 (gmt 0)

10+ Year Member



In the IIS Management Console, you can set the SMTP service to use a Smart Host (Your regular mail server)

That server may also need to be configured to relay mail received from your IIS server.

kosmoraios

1:12 pm on May 28, 2004 (gmt 0)

10+ Year Member



You guys are awesome. Thanks alot. Can anyone give me a Java code snippet to use the CDONTS mail object in ASP?

I wrote the page in Dreamweaver Ultradev 4 and selected java as the page language in the application server preferences, because I had some other java for timestamping and focusing etc and I wanted to be consistant. I can re-create the dynamic form part in VBScript if need be.

I also need to define my field values that I want in the email, right?
like this?
FieldName = Request.Form("Field_Name")
and then I put that in the CDONTS mail object like this?
objMailer.Body = Email received from &FieldName regarding &Subject

Thanks for your help, people.

dotme

1:22 pm on May 28, 2004 (gmt 0)

10+ Year Member



objMailer.Body = "Email received from " & FieldName & " regarding " & Subject

(Note the " marks)

:-)

kosmoraios

1:25 pm on May 28, 2004 (gmt 0)

10+ Year Member



Thanks for your help, dotme - it's greatly appreciated.
I am going to try here in a few minutes. We'll see what happens - Im sure I'll be back

(-:

kosmoraios

7:05 pm on May 28, 2004 (gmt 0)

10+ Year Member



I get an "expected end of statement on line 110 which is

objMailer.Body = "Helpdesk request from " &strFrom " & vbCrLf "ReqType: " &strType & vbCrLf "Subject: " &strSubject & vbCrLf "Priority: " &strPriority & vbCrLf "Desired Time: " &strDesTime &vbCrLf "Latest Time: " &strMaxTime & vbCrLf "Details: " &strDetails & vbCrLf "!"

The entire snippet of the mailer portion is

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

strFrom = Request.Form("UserName")
strSubject=Request.Form("subject")
strType=Request.Form("Type")
strPriority=Request.Form("Priority")
strDesTime=Request.Form("DesTime")
strMaxTime=Request.Form("MaxTime")
strDetails=Request.Form("Details")

Set objMailer = Server.CreateObject("CDONTS.NewMail")
objMailer.From = "Global User"
objMailer.To = "noakes@teamglobal.com"
objMailer.Subject = "Helpdesk Request recieved from " &strFrom
objMailer.BodyFormat = 0

objMailer.MailFormat = 0
objMailer.Importance = 2
objMailer.Body = "Helpdesk request from " &strFrom " & vbCrLf "ReqType: " &strType & vbCrLf "Subject: " &strSubject & vbCrLf "Priority: " &strPriority & vbCrLf "Desired Time: " &strDesTime &vbCrLf "Latest Time: " &strMaxTime & vbCrLf "Details: " &strDetails & vbCrLf
objMailer.Send
Set objMailer = nothing

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%

What am I doing wrong? Does anyone have any vb reference-type sites I can refer to? Thanks!

john_k

7:18 pm on May 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your code wrapped in your post, then you are simply missing a "&" character before "Priority: ".

If it is actually appearing on three lines in your code, then you are missing that "&" character AND you need to add in some line continuation (underscore) characters at the end of the first and second line.

kosmoraios

7:28 pm on May 28, 2004 (gmt 0)

10+ Year Member



Yeah, code was wrapped in post

That's what it was. Missing & character. Thank you!

Now to see if the thing sends mail.

kosmoraios

3:22 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



Ok. It acts like it sends but it isn't going out. I have set the SMTP server in the extensions preferences. Is there a way to view the que or see whats going on? I am not very familiar with IIS, more familiar with apache. If anyone knows a better way to make a form insert a record and send an email at the same time, please enlighten me. Thanks!

dotme

1:41 pm on Jun 2, 2004 (gmt 0)

10+ Year Member



Okay - this might be an easy fix. CDONTS object has nothing to do with the SMTP Server settings on a Frontpage Web. You are actually calling the "SMTP Server" configured in the IIS Management Console.

Some things to check...

Open IIS Management Console - make sure the Default SMTP Virtual Server is started. Also check in Services for "Simple Mail Transport" service (W2K) and make sure it is running.

If the answer to both of the above is "yes", check the folders for the SMTP Service. These are by default at C:\InetPUB\Mailroot

If files are in Pickup, the service isn't/wasn't running. If files are in badmail or drop, you may have a firewall issue. Open the files in badmail or drop with NOTEPAD and they may contain information on why the emails were undeliverable. If the reason for non-delivery is not clear, post again with some info and we'll go from there.

:-)

dotme

1:46 pm on Jun 2, 2004 (gmt 0)

10+ Year Member



Oh - almost forgot. You would probably want to review permissions in the IIS Management Console for the SMTP Server as well, to make sure it is not configured as an open relay.

kosmoraios

2:54 pm on Jun 2, 2004 (gmt 0)

10+ Year Member



dotme - Thanks for your help. I used the persits mailsender and re-wrote the script. Everything works fine. I had to set the smart host in the IIS SMTP delivery options. I still can't figure out why the CDONTS didn't work - I could put a mime header on a text file, drop it in pickup, and it would go out. The error that I was getting in the badmail folder was something about the pickup directory. Anyway, it's sending, its inserting records, it works great. I need to build a form to query the database, now. Also, I need to figure out how to write some script that will not allow duplicate entries into the database. Thanks for your help, everyone.