This topic is locked

Email Confirmation when new record added

9/21/2005 11:19:59 PM
ASPRunnerPro General questions
cagleyleslie author

I've added the following to the _add page, and it works. It sends an email notification when someone adds a record to the database. I also want to send the data that was just posted in the body of the email. How would I refer to field names, so I can include them in the email body? Thanks!
' send email

Dim objCDOSYSCon

Set objCDOSYSMail = Server.CreateObject("CDO.Message")

Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver";) = "SMTP server"

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport";) = 25

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing";) = 2

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout";) = 60

objCDOSYSCon.Fields.Update

Set objCDOSYSMail.Configuration = objCDOSYSCon

objCDOSYSMail.From = "webmaster@company.com"

objCDOSYSMail.To = "user@company.com"

objCDOSYSMail.Bcc = "user@company.com"

objCDOSYSMail.Subject = "New request posted on website"

objCDOSYSMail.HTMLBody = "want to display data just posted here"

objCDOSYSMail.Send

Set objCDOSYSMail = Nothing

Set objCDOSYSCon = Nothing

Sergey Kornilov admin 9/22/2005

Hi,
you need to find

rs.Update

rs.Close
rs("Field1")
rs("Field2")


and insert your code right before this snippet.
So you'll be able to refer to data entered by user using this syntax (where Field1 and Field2 are your fieldnames).

501262 9/22/2005

same question- and I have this error
Technical Information (for support personnel)
Error Type:

CDO.Message.1 (0x80040213)

The transport failed to connect to the server.

/test/test_em/Table1_add.asp, line 370
Browser Type:

Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Page:

POST 1250 bytes to /test/test_em/Table1_add.asp
POST Data:

error '80020009'

Exception occurred.
/iisHelp/common/500-100.asp, line 223 [/b]

Sergey Kornilov admin 9/22/2005

Do not forget to put real SMTP server name there:

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver";) = "SMTP server"


If you use local SMTP server put localhost there. Make sure other fields are correct as well.

cagleyleslie author 9/22/2005

Hi,

you need to find
and insert your code right before this snippet.
So you'll be able to refer to data entered by user using this syntax (where Field1 and Field2 are your fieldnames).



Thanks Sergey for the quick response. But I don't see the code you're talking about. On the _add page? I just see this (see below). I don't see any reference to rs.(Field1") right under the rs.Update and rs.Close. Thanks!
rs.Update

rs.Close
message="<div class=message><<< " & "Record was added" & " >>></div>"
end if

cagleyleslie author 9/22/2005

Oh never mind! I got it! Before, I was putting the email code in between 'message' and 'end if.' But this time I added it before 'rs.Update' and it worked! Thanks again!
rs.Update

rs.Close
message="<div class=message><<< " & "Record was added" & " >>></div>"
end if

A
apscnjohnnie 9/26/2005

I am really liking the info on the email notification but really can't seem to figure out how to include the field data in the message body. I have entered it in as it is shown in these posts right beneath the rs.Close line
rs.Update

rs.Close
rs("Field1")
rs("Field2")
And I have entered it into the body line like the following
objCDOSYSMail.HTMLBody = "rs(field1")"
But both return errors the latter method will not even bring up the add page and the former brings up an error when you hit save.
Any ideas in what I am missing?

cagleyleslie author 9/26/2005

You have to add it BEFORE the rs.Close bit, and no quotes around it:
objCDOSYSMail.HTMLBody = rs("FieldName")
If you want to add other stuff, you do have to put quotes around that.
objCDOSYSMail.HTMLBody = "<table cellpadding=6 border=1 cellspacing=0 bordercolor=white bgcolor=efefef><tr><td><font face=arial size=2>Card Name:</td><td><font face=arial size=2>" & rs("CardName") & "</td></tr></table>"
rs.Update

rs.Close

swat 9/29/2005

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver";) = "SMTP server"
how can I find out my SMTP server-thanks

swat 9/29/2005

Also- Can I use this email founction in the ...._list.asp file or ...search.asp file - let say user selects to see data from advance search or regular search field , is it possible to not display data but just email to his/her email address?

thx

swat 9/29/2005

CDO.Message.1 error '80040213'
The transport failed to connect to the server.
/klklko/fa/FA_add.asp, line 597

Sergey Kornilov admin 9/30/2005

Swat,
to determine your SMTP server please contact with your hosting administrator or use SMTP settings from your email client.

orit 12/7/2005

I would like to send e-mail confirmation only when the user who enters the records decides that he want e-mail notification to be sent.

What I think to do is to add a checkbox saying "send notification". if the user marks this checkbox, an e-mail with the content of the record will be sent.
Can someone please suggest how to implement this?
Thanks