...

View Full Version : CDOSYS email



RedBravo
09-14-2005, 04:27 PM
Hi,
Need some help please changing a script from CDONTS mail to CDOSYS mail.

Can someone have a look at these two scripts, register.asp and storefuncs.asp and tell me what i am doing wrong. I want to generate an email to customers confirming that they have registered. Everything else in the scripts works fine updating database etc but won't send an email - I don't get an error message either.

Thanks in advance
Rob

storfuncs.asp
<%
'==========================
' Common Functions
'==========================
FUNCTION fixQuotes( theString )
fixQuotes = REPLACE( theString, "'", "''" )
END FUNCTION


SUB addCookie( theName, theValue )
Response.Cookies( theName ) = theValue
Response.Cookies( theName ).Expires = "July 31, 2010"
Response.Cookies( theName ).Path = "/"
Response.Cookies( theName ).Secure = FALSE
END SUB



FUNCTION checkpassword( byVal username, byVal password, byRef Con )
sqlString = "SELECT user_id FROM users " &_
"WHERE user_username='" & username & "' " &_
"AND user_password='" & password & "'"
SET RS = Con.Execute( sqlString )
IF RS.EOF THEN
checkpassword = - 1
ELSE
checkpassword = RS( "user_id" )
addCookie "username", username
addCookie "password", password
END IF
END FUNCTION


FUNCTION SELECTED( firstVal, secondVal )
IF cSTR( firstVal ) = cSTR( secondVal ) THEN
SELECTED = " SELECTED "
ELSE
SELECTED = ""
END IF
END FUNCTION

SUB errorForm( errorMSG, backpage )
%>
<html>
<head><title>Problem</title></head>
<body bgcolor="lightyellow">

<center>
<table width="500" border=1
cellpadding=5 cellspacing=0>
<tr>
<td>
<font face="Arial" size="3" color="darkblue"><b>
There was a problem with the information you entered:
</b></font>
<font size="2" color="red"><b>
<br><%=errorMSG%>
</b></font>
<br>
<form method="post" action="<%=backpage%>">
<input name="error" type="hidden" value="1">
<% formFields %>
<input type="submit" value="Return">
</form>
</td>
</tr>
</table>
</center>

</body>
</html>
<%
Response.End
END SUB


SUB formFields
FOR each item in Request.Form
%>
<input name="<%=item%>" type="hidden"
value="<%=Server.HTMLEncode( Request( item ) )%>">
<%
NEXT
END SUB

'===========================
' Registration Functions
'===========================
SUB sendNewUserMail(sUserName, sUserMail, fHtml)

Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
Dim sSql

Dim objMail

Set newMailObj = CreateObject("CDO.Message")

objMailObj.From = "sales@mybusiness.com"
objMailObj.To = sUserMail
objMailObj.Subject = "mybusiness.com.au"

if fHtml = "0" then
objMail.BodyFormat = CdoBodyFormatText
objMail.MailFormat = CdoMailFormatMime
sMailBody = "Dear " & sUserName & "," & vbNewLine & vbNewLine
sMailBody = sMailBody & " Thank you for registering at our site!" & vbNewLine & vbNewLine
sMailBody = sMailBody & " We look forward to serving you in the future. "
sMailBody = sMailBody & "Visit us again soon at http://www.mysite.com." & vbNewLine & vbNewLine
sMailBody = sMailBody & "Sincerely yours," & vbNewLine & vbNewLine
sMailBody = sMailBody & "David," & vbNewLine
sMailBody = sMailBody & "CEO."
objMail.TextBody = sMailBody
else
objMail.TextBodyFormat = CdoBodyFormatHTML
objMail.MailFormat = CdoMailFormatMime
objMail.ContentBase = "http://www.mysite.com.au/"
objMail.ContentLocation = "????"
sMailBody = "<HTML><HEAD><TITLE>Thanks from mycompany.com</TITLE></HEAD>"
sMailBody = sMailBody & "<BODY><table width=""640"" border=""0"" bgcolor=""#ffffff"" cellspacing=""0"" cellpadding=""0"">"

sMailBody = sMailBody & "<tr><td colspan=""2""><hr width=""640""></td></tr></table>"
sMailBody = sMailBody & "<font face=""Arial"" size=""2""><p>Dear " & sUserName & ", "
sMailBody = sMailBody & "<p>Thank you for registering at our site!<p>We look forward to serving you in the future. "
sMailBody = sMailBody & "Visit us again soon at <a href=""http://www.mybusiness.com"">"
sMailBody = sMailBody & "http://www.myste.com</a>.<br><br>Sincerely yours,<br><br>David"
sMailBody = sMailBody & "<br>CEO</font></BODY></HTML>"
objMail.TextBody = sMailBody
end if
objMail.Send
Set objMail = Nothing
END SUB

SUB addUser
' Get Registration Fields
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
contact = TRIM( Request( "contact" ) )
store = TRIM( Request( "store" ) )
phone = TRIM( Request( "phone" ) )
fax = TRIM( Request( "fax" ) )
street = TRIM( Request( "street" ) )
city = TRIM( Request( "city" ) )
state = TRIM( Request( "state" ) )
pcode = TRIM( Request( "pcode" ) )

html = TRIM( Request( "html" ) )
if html = "Yes" then
html = "1"
else
html = "0"
end if


' Check For Required Fields
backpage = Request.ServerVariables( "SCRIPT_NAME" )
IF newusername = "" THEN
errorForm "You must enter a username.", backpage
END IF
IF newpassword = "" THEN
errorForm "You must enter a password.", backpage
END IF
IF email = "" THEN
errorForm "You must enter your email address.", backpage
END IF
IF street = "" THEN
errorForm "You must enter your street address.", backpage
END IF
IF city = "" THEN
errorForm "You must enter your city.", backpage
END IF
IF state = "" THEN
errorForm "You must enter your state.", backpage
END IF
IF pcode = "" THEN
errorForm "You must enter your post code.", backpage
END IF
IF contact = "" THEN
errorForm "You must enter a contact name.", backpage
END IF
IF store = "" THEN
errorForm "You must enter your store name.", backpage
END IF
IF phone = "" THEN
errorForm "You must enter your phone number.", backpage
END IF
IF fax = "" THEN
errorForm "You must enter your fax number.", backpage
END IF

' Check for Necessary Field Values
IF invalidEmail( email ) THEN
errorForm "You did not enter a valid email address", backpage
END IF


' Check whether username already registered
IF alreadyUser( newusername ) THEN
errorForm "Please choose a different username.", backpage
END IF

' Add New User to Database
sqlString = "INSERT INTO users ( " &_
"user_username, " &_
"user_password, " &_
"user_email, " &_
"user_contact, " &_
"user_store, " &_
"user_phone, " &_
"user_fax, " &_
"user_street, " &_
"user_city, " &_
"user_state, " &_
"user_pcode, " &_
"user_html " &_


") VALUES ( " &_
" '" & fixQuotes( newusername ) & "', " &_
" '" & fixQuotes( newpassword ) & "', " &_
" '" & fixQuotes( email ) & "', " &_
" '" & fixQuotes( contact ) & "', " &_
" '" & fixQuotes( store ) & "', " &_
" '" & fixQuotes( phone ) & "', " &_
" '" & fixQuotes( fax ) & "', " &_
" '" & fixQuotes( street ) & "', " &_
" '" & fixQuotes( city ) & "', " &_
" '" & fixQuotes( state ) & "', " &_
" '" & fixQuotes( pcode ) & "', " &_
" " & html & " " &_
")"



Con.Execute sqlString

' Use the new username and password
username = newusername
password = newpassword

' Add Cookies
addCookie "username", username
addCookie "password", password
END SUB


SUB updateUser
' Get Registration Fields
contact = TRIM( Request( "contact" ) )
store = TRIM( Request( "store" ) )
phone = TRIM( Request( "phone" ) )
fax = TRIM( Request( "fax" ) )
street = TRIM( Request( "street" ) )
city = TRIM( Request( "city" ) )
state = TRIM( Request( "state" ) )
pcode = TRIM( Request( "pcode" ) )
ccnumber = TRIM( Request( "ccnumber") )
cctype = TRIM( Request( "cctype") )
ccexpires = TRIM( Request( "ccexpires") )
ccname = TRIM( Request( "ccname") )


' Check For Required Fields
backpage = "checkout.asp"
IF street = "" THEN
errorForm "You must enter your street address.", backpage
END IF
IF city = "" THEN
errorForm "You must enter your city.", backpage
END IF
IF state = "" THEN
errorForm "You must enter your state.", backpage
END IF
IF pcode = "" THEN
errorForm "You must enter your post code.", backpage
END IF
IF contact = "" THEN
errorForm "You must enter a contact name.", backpage
END IF
IF store = "" THEN
errorForm "You must enter your store name.", backpage
END IF
IF phone = "" THEN
errorForm "You must enter your phone number.", backpage
END IF
IF fax = "" THEN
errorForm "You must enter your fax number.", backpage
END IF



' Update user information in the database
sqlString = "UPDATE users SET " &_
"user_contact='" & fixQuotes( contact ) & "', " &_
"user_store='" & fixQuotes( store ) & "', " &_
"user_phone='" & fixQuotes( phone ) & "', " &_
"user_fax='" & fixQuotes( fax ) & "'," &_
"user_street='" & fixQuotes( street ) & "'," &_
"user_city='" & fixQuotes( city ) & "'," &_
"user_state='" & fixQuotes( state ) & "', " &_
"user_pcode='" & fixQuotes( pcode ) & "'," &_
"user_ccnumber='" & fixQuotes( ccnumber ) & "'," &_
"user_cctype='" & fixQuotes( cctype ) & "'," &_
"user_ccexpires='" & fixQuotes( ccexpires ) & "'," &_
"user_ccname='" & fixQuotes( ccname ) & "' " &_
"WHERE user_id=" & userID


Con.Execute sqlString
END SUB



FUNCTION invalidEmail( email )
IF INSTR( email, "@" ) = 0 OR INSTR( email, "." ) = 0 THEN
invalidEmail = TRUE
ELSE
invalidEmail = FALSE
END IF
END FUNCTION




-------------------------------------------------------------------------
SCRIPT NUMBER 2 - starts here!!!
-------------------------------------------------------------------------
register.asp

<%
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
contact = TRIM( Request( "contact" ) )
store = TRIM( Request( "store" ) )
phone = TRIM( Request( "phone" ) )
fax = TRIM( Request( "fax" ) )
street = TRIM( Request( "street" ) )
city = TRIM( Request( "city" ) )
state = TRIM( Request( "state" ) )
pcode = TRIM( Request( "pcode" ) )
ccnumber = TRIM( Request( "ccnumber" ) )
cctype = Request( "cctype" )
ccexpires = TRIM( Request( "ccexpires" ) )
ccname = TRIM( Request( "ccname" ) )
html = TRIM( Request ( "html" ) )


submitpage = Request.ServerVariables( "SCRIPT_NAME" )
%>

<html>
<head><title>Register</title></head>
<body bgcolor="#cfcfff">
<table width="75%" border="0" align="center">
<tr>
<td width="31%"><font face="Arial, Helvetica, sans-serif" size="2" color="6699ff">Registration and Login Page</font></td>
</tr>
</table>
<hr>
<table width="500" border="1"
cellpadding=4 cellspacing=0 align="center">
<tr>
<td>
<form method="post" action="<%=submitpage%>">
<div align="left">
<input name="login" type="hidden" value="1">
<input name="pid" type="hidden" value="<%=productID%>">
<font size="2" color="#6699ff" face="Arial"> </font>
<table width="84%" border="0" align="center">
<tr>
<td colspan="3"> <font size="2" color="#6699ff" face="Arial"> <b>LOGIN</b></font></td>
</tr>
<tr>
<td colspan="3"><font size="2" color="#6699ff" face="Arial"></font><font size="2" color="#6699ff" face="Arial">If
you are already a user please enter your username and password:
</font></td>
</tr>
<tr>
<td width="31%"><font size="2" color="#6699ff" face="Arial"><b>username:</b></font></td>
<td width="34%"><font size="2" color="#6699ff" face="Arial">
<input name="username" size="20">
</font></td>
<td width="35%"><font size="2" color="#6699ff" face="Arial">
<input type="submit" value="Login" name="submit">
</font></td>
</tr>
<tr>
<td width="31%"><font size="2" color="#6699ff" face="Arial"><b>password:</b></font></td>
<td width="34%"><font size="2" color="#6699ff" face="Arial">
<input name="password" size="20">
</font></td>
<td width="35%">&nbsp;</td>
</tr>
</table>
<font size="2" color="#6699ff" face="Arial"></font> </div>
</form>
</td>
</tr>
<tr>
<td bgcolor=""#6699ff">
<div align="left"></div>
</td>
</tr>
<tr>
<td>
<form method="post" action="<%=submitpage%>">
<div align="left">
<input name="register" type="hidden" value="1">
<input name="pid" type="hidden" value="<%=productID%>">
<font size="2" color="#6699ff" face="Arial"> </font>
<table width="91%" border="0" align="center">
<tr>
<td width="97%">
<table width="96%" border="0" align="center">
<tr>
<td colspan="4"> <b><font size="2" color="#6699ff" face="Arial">REGISTER</font></b></td>
</tr>
<tr>
<td colspan="4"><font size="2" color="#6699ff" face="Arial">If
you are not already registered please enter a username &amp;
password: </font></td>
</tr>
<tr>
<td colspan="2"><font size="2" color="#6699ff" face="Arial"><b>username:<br>
</b></font></td>
<td colspan="2"><font size="2" color="#6699ff" face="Arial">
<input name="newusername" size=20 maxlength=20 value="<%=Server.HTMLEncode( newusername )%>">
</font><font size="2" color="#6699ff" face="Arial"> </font></td>
</tr>
<tr>
<td colspan="2"><font size="2" color="#6699ff" face="Arial"><b>password:</b></font></td>
<td colspan="2"><font size="2" color="#6699ff" face="Arial">
<input name="newpassword" size=20 maxlength=20 value="<%=server.HTMLEncode( newpassword )%>">
</font></td>
</tr>
<tr>
<td height="18" colspan="2"><font size="2" color="#6699ff" face="Arial"><b>email
address:</b></font></td>
<td height="18" colspan="2"><font size="2" color="#6699ff" face="Arial">
<input name="email" size=30 maxlength=75 value="<%=Server.HTMLEncode( email )%>">
<br><input name="html" type="checkbox" value="Yes" <% if Server.HTMLEncode( html ) = "Yes" then %>CHECKED<% end if %>>
<b>I can read E-Mail formatted in HTML.</b>
</font>
</font></td>
</tr>
<tr>
<td colspan="4" height="18"><font face="Arial" size="1" color="6699ff">Note:
</font>
<hr>
<font face="Arial" size="2" color="6699ff"><b>Enter your
contact details here:</b></font></td>
</tr>
<tr>
<td width="14%"><b><font face="Arial, Helvetica, sans-serif" color="6699ff" size="2">Contact Name:</font></b></td>
<td colspan="3"><font size="2" color="#6699ff" face="Arial">
<input name="contact" size=50 maxlength=50 value="<%=Server.HTMLEncode( contact )%>">
</font></td>
</tr>
<tr>
<td width="14%"><font color="6699ff" face="Arial, Helvetica, sans-serif" size="2">Store:</font></td>
<td colspan="3"><font size="2" color="#6699ff" face="Arial">
<input name="store" size=50 maxlength=50 value="<%=Server.HTMLEncode( store )%>">
</font></td>
</tr>
<tr>
<td width="14%"><font face="Arial, Helvetica, sans-serif" size="2" color="6699ff">Phone:</font></td>
<td width="29%">
<input name="phone" size=20 maxlength=50 value="<%=Server.HTMLEncode( phone )%>">
</td>
<td width="12%"><font color="6699ff" face="Arial, Helvetica, sans-serif" size="2">Fax:</font></td>
<td width="45%">
<input name="fax" size=20 maxlength=50 value="<%=Server.HTMLEncode( fax )%>">
</td>
</tr>
<tr>
<td width="14%"><font face="Arial, Helvetica, sans-serif" size="2" color="6699ff">Address:</font></td>
<td colspan="3">
<input name="street" size=50 maxlength=50 value="<%=Server.HTMLEncode( street )%>">
</td>
</tr>
<tr>
<td width="14%"><font color="6699ff" size="2" face="Arial, Helvetica, sans-serif">Town/City</font></td>
<td colspan="3">
<input name="city" size=50 maxlength=50 value="<%=Server.HTMLEncode( city )%>">
</td>
</tr>
<tr>
<td width="14%"><font color="6699ff" size="2" face="Arial">State:</font></td>
<td width="29%">
<input name="state" size=5 maxlength=3 value="<%=Server.HTMLEncode( state )%>">
</td>
<td width="12%"><font size="2" color="#6699ff" face="Arial">Postcode:</font></td>
<td width="45%"><font size="2" color="#6699ff" face="Arial">
<input name="pcode" size=6 maxlength=4 value="<%=Server.HTMLEncode( pcode )%>">
</font></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
<td width="12%">&nbsp;</td>
<td width="45%"><font size="2" color="#6699ff" face="Arial">
<input type="submit" value="Register" name="submit2">
</font></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</td>
</tr>
</table>

</body>
</html>

TheShaner
09-14-2005, 04:42 PM
Woah, that's a lot to go through, but looking at your mail, that's of course the problem. It's still set up for CDONTS.

Click on this link (http://www.powerasp.com/content/new/sending_email_cdosys.asp) to learn what you need to do to use CDOSYS.

-Shane

RedBravo
09-15-2005, 12:51 PM
Sorry, you're right - I should have edited it somewhat before posting.

I changed the email to this simple one to test if i can get it to work ok:

SUB sendNewUserMail

Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
Dim objMail

Set newMailObj = CreateObject("CDO.Message")

objMailObj.From = "sales@mycompany.com"
objMailObj.To = "newuser@emailaddress.com"
objMailObj.Subject = "Welcome"
objMail.TextBody = "this is the text"

objMail.Send
Set objMail = Nothing
END SUB

Still nothing happens - no email or error message.
But i think i figured out what the problem is, i can't see anywhere in a corresponding script that would "trigger" the email.
If you think this could be the problem can you give me any clues as to what i should be looking for.
Thanks

NancyJ
09-15-2005, 01:27 PM
But i think i figured out what the problem is, i can't see anywhere in a corresponding script that would "trigger" the email.

dumb question but... thats a sub, you are actually calling it right? not just using that code on its own?

RedBravo
09-15-2005, 03:16 PM
Hi Nancy,

It's pretty obvious i'm a newbie to asp.

I want to be able to call this script from a html form to send an email when a new user submits their details or places an order

neocool00
09-15-2005, 03:25 PM
@RedBravo,
In your ASP code where you want to send an e-mail, use this code:

Call sendNewUserMail
If you want to make the e-mail more dynamic, you could change your sub to this:

SUB sendNewUserMail(sTo, sFrom, sMsg, sSubject, sTextBody)
Dim objMail
Set newMailObj = CreateObject("CDO.Message")
objMailObj.From = sFrom
objMailObj.To = sTo
objMailObj.Subject = sMsg
objMail.TextBody = sTextBody
objMail.Send
Set objMail = Nothing
END SUB
Then to send an e-mail you would just call the sub and pass in the values for the parameters.

Call sendNewUserMail("newuser@emailaddress.com", "sales@mycompany.com", "Welcome", "this is the text")

RedBravo
09-16-2005, 01:06 PM
Thanks for the excellent assistance.

Got it to work fine to send an email to a specified email address for testing purposes - but i want to send a confirmation email to the email address of a customer who just logged in.

I've got another email script in that works to send email to customers email addresses - can i combined these two scripts? and how? if not is there another way to do this?

Script 1 (works fine)
-----------------------
SUB sendNewUserMail
Dim ObjSendMail
Set ObjSendMail = Server.CreateObject("CDO.Message")
ObjSendMail.To = "newuser@home.com"
ObjSendMail.Subject = "Hello"
ObjSendMail.From = "sales@mycompany.com"
ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send

Set ObjSendMail = Nothing
END SUB

Call sendNewUserMail
------------------------
Script 2 - Starts here
-----------------------
<%

Dim Con
Dim rs

'DSN Less Connection to the Database
strDBPath = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\wwwroot\mycompany\database\dataDB.mdb"
' Create an ADO Connection to connect to the database.
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open strDBPath
Set rs = Server.CreateObject( "ADODB.Recordset" )

Dim sMsg
Dim sTo
Dim sFrom
Dim sSubject
Dim sTextBody
Dim sSql


For i = 1 to Request.Form("sendEMail").Count
sSql = "select user_username from users where user_email='"& Request.Form("sendEMail")(i) &"'"
rs.Open sSql, Con, adOpenForwardOnly, adLockReadOnly

Dim objMail

Set objMail = CreateObject("CDO.Message")

objMail.From = "sales@mycompany.com"
objMail.To = Request.Form("sendEMail")(i)
objMail.Subject = Request.Form("subject")


objMail.TextBody = "Dear " & rs.Fields("user_username") & "," & vbNewLine & vbNewLine
objMail.TextBody = objMail.TextBody & Request.Form("messageText")

objMail.Send
Set objMail = Nothing
rs.Close()
next

Con.Close()
Set rs = Nothing
Set Con = Nothing

%>

NancyJ
09-16-2005, 02:12 PM
<%

Dim Con
Dim rs

'DSN Less Connection to the Database
strDBPath = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\wwwroot\mycompany\database\dataDB.mdb"
' Create an ADO Connection to connect to the database.
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open strDBPath
Set rs = Server.CreateObject( "ADODB.Recordset" )

Dim sSql


For i = 1 to Request.Form("sendEMail").Count
sSql = "select user_username from users where user_email='"& Request.Form("sendEMail")(i) &"'"
rs.Open sSql, Con, adOpenForwardOnly, adLockReadOnly


emailTo = Request.Form("sendEMail")(i)
Subject = Request.Form("subject")


TextBody = "Dear " & rs.Fields("user_username") & "," & vbNewLine & vbNewLine
TextBody = TextBody & Request.Form("messageText")

call sendEmail(EmailTo, Subject, textbody)

rs.Close()
next

Con.Close()
Set rs = Nothing
Set Con = Nothing

'######################################
'### functions ###
'######################################
SUB sendNewUserMail(email, subject, body)
Dim ObjSendMail
Set ObjSendMail = Server.CreateObject("CDO.Message")
ObjSendMail.To = email
ObjSendMail.Subject = subject
ObjSendMail.From = "sales@mycompany.com"
ObjSendMail.TextBody = body

ObjSendMail.Send

Set ObjSendMail = Nothing
END SUB

%>

RedBravo
09-16-2005, 03:50 PM
Thanks Nancy,

Insert this into my sub routine.

Unfortunatley it doesn't seem to be being called.
- script executes without a sending an email or displaying error message.

Doesn't make any difference whether "Call sendNewUserMail" is included or not - only if inserted after END SUB" does it give an error message
Rgds
Rob

NancyJ
09-16-2005, 04:09 PM
ignore the old subroutine... get rid of it completely, blank it from your mind etc ;)

This is the subroutine you should use.


SUB sendNewUserMail(email, subject, body)
Dim ObjSendMail
Set ObjSendMail = Server.CreateObject("CDO.Message")
ObjSendMail.To = email
ObjSendMail.Subject = subject
ObjSendMail.From = "sales@mycompany.com"
ObjSendMail.TextBody = body

ObjSendMail.Send

Set ObjSendMail = Nothing
END SUB

Whenever you want to send an email use this:

call sendEmail(EmailTo, Subject, textbody)
where emailto, subject and textbody are variables that contain the relevant information.

For the email you want to send to your users (script 2 in your post), you would do this:


<%

Dim Con
Dim rs

'DSN Less Connection to the Database
strDBPath = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=D:\wwwroot\mycompany\database\dataDB.mdb"
' Create an ADO Connection to connect to the database.
Set Con = Server.CreateObject( "ADODB.Connection" )
Con.Open strDBPath
Set rs = Server.CreateObject( "ADODB.Recordset" )

Dim sSql


For i = 1 to Request.Form("sendEMail").Count
sSql = "select user_username from users where user_email='"& Request.Form("sendEMail")(i) &"'"
rs.Open sSql, Con, adOpenForwardOnly, adLockReadOnly


emailTo = Request.Form("sendEMail")(i)
Subject = Request.Form("subject")


TextBody = "Dear " & rs.Fields("user_username") & "," & vbNewLine & vbNewLine
TextBody = TextBody & Request.Form("messageText")

call sendEmail(EmailTo, Subject, textbody)

rs.Close()
next

Con.Close()
Set rs = Nothing
Set con = Nothing

RedBravo
09-17-2005, 03:12 PM
I know i'm a bit dopey Nancy but i still can't get it to send to a new user.

But I was thinking that as this info is being passed from a form to be added to the database the info should already be available without reopening the recordset. is this correct?

This is the original code written for CDONTS which i know used to work - it might be easier just to edit this to work in CDOSYS.
this is the code as well as the start of the sub to add new user.
---------
SUB sendNewUserMail(sUserName, sUserMail)
Dim newMailObj
Dim sMailBody

Set newMailObj = CreateObject("CDONTS.Newmail")
newMailObj.From = "sales@mycompany.com"
newMailObj.To = sUserMail
newMailObj.Subject = "Welcome"

newMailObj.BodyFormat = CdoBodyFormatText
newMailObj.MailFormat = CdoMailFormatMime
sMailBody = "Dear " & sUserName & "," & vbNewLine & vbNewLine
sMailBody = sMailBody & " Thank you for registering " & vbNewLine & vbNewLine
sMailBody = sMailBody & " We look forward to serving you in the future. "
sMailBody = sMailBody & "David," & vbNewLine
sMailBody = sMailBody & "CEO."
newMailObj.Body = sMailBody

newMailObj.Send
Set newMailObj = Nothing
END SUB

SUB addUser
' Get Registration Fields
newusername = TRIM( Request( "newusername" ) )
newpassword = TRIM( Request( "newpassword" ) )
email = TRIM( Request( "email" ) )
contact = TRIM( Request( "contact" ) )
store = TRIM( Request( "store" ) )
phone = TRIM( Request( "phone" ) )
fax = TRIM( Request( "fax" ) )
street = TRIM( Request( "street" ) )
city = TRIM( Request( "city" ) )
state = TRIM( Request( "state" ) )
pcode = TRIM( Request( "pcode" ) )

' Add New User to Database
sqlString = "INSERT INTO users ( " &_
"user_username, " &_
"user_password, " &_
"user_email, " &_
"user_contact, " &_
"user_store, " &_
"user_phone, " &_
"user_fax, " &_
"user_street, " &_
"user_city, " &_
"user_state, " &_
"user_pcode " &_

minhas4all
09-18-2005, 05:43 PM
thanks you all
you really doing well
but is there some one who can write in details for sendig mail so its better for all like us those are newbies
thanks once again

NancyJ
09-18-2005, 07:03 PM
ok, replace your current email sub with this:

SUB sendNewUserMail(sUserName, sUserMail)
Dim ObjSendMail
Set ObjSendMail = Server.CreateObject("CDO.Message")
ObjSendMail.To = sUserMail
ObjSendMail.Subject = "Welcome"
ObjSendMail.From = "sales@mycompany.com"
sMailBody = "Dear " & sUserName & "," & vbNewLine & vbNewLine
sMailBody = sMailBody & " Thank you for registering " & vbNewLine & vbNewLine
sMailBody = sMailBody & " We look forward to serving you in the future. "
sMailBody = sMailBody & "David," & vbNewLine
sMailBody = sMailBody & "CEO."
ObjSendMail.TextBody = sMailBody
ObjSendMail.Send
Set ObjSendMail = Nothing
END SUB

RedBravo
09-19-2005, 02:56 PM
Thanks for your help Nancy,
Getting close now - get an error message now: "At least one recipient is required, but none were found" so the info is not being located.

Can you please confirm if i'm on the right track here;
The email address of the customer is passed to the script using the "input name" on the form?
<input name="email" value="<%=Server.HTMLEncode( email )%>">

If this is correct it still can't find it

NancyJ
09-19-2005, 03:26 PM
how are you calling the function?
If your old function did work then this new one should, the function is the only thing you should have changed.
You had a function that sent this email, this function works in exactly the same way except it uses cdosys email rather than cdonts.
You need to pass the email address and username as paramaters to the functions, exactly the same as you would have done before.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum