DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP (http://www.daniweb.com/forums/forum62.html)
-   -   Sending an Automatic Email (http://www.daniweb.com/forums/thread199516.html)

whisper_101 Jun 24th, 2009 11:04 am
Sending an Automatic Email
 
Hi Guys

I have been working on an Automatic Email Function. The code returns two different email addresses which are used to send emails to. The problem is - in second email sent the Body of the text is repeated twice i.e.

In the First Email Sent:

Welcome to the Jobs by Email Service

Wigs

But in the Second Email Sent:

Welcome to the Jobs by Email Service

Wigs

Welcome to the Jobs by Email Service

Wigs

<!--Connection To Database -->
<!-- #INCLUDE FILE="Openconnection-for-local-use.asp" -->

<!--Email Alert -->

<%

Dim rsEmailAlert_numRows

strSQL =  "SELECT  Table_Salon_Info.S_Skills_Required, Table_Salon_Info.S_Skills_Location, Table_Email_Alert.A_Email FROM Table_Salon_Info INNER JOIN Table_Email_Alert ON Table_Salon_Info.S_Skills_Required =  Table_Email_Alert.A_Stylist_Type WHERE    (Table_Salon_Info.S_Id = 1) AND (Table_Salon_Info.S_Skills_Location = 'London')"

Set rsEmailAlert = Server.CreateObject("ADODB.Recordset")
               
rsEmailAlert.open strSQL,Conn

rsEmailAlert_numRows = 0
%>

<!--LOOP AROUND THE ARRAY TO RETRIEVE ALL VALUES -->

<%
    Dim Repeat1__numRows
    Repeat1__numRows = -1
    Dim Repeat1__index
    Repeat1__index = 0
    rsEmailAlert_numRows = rsEmailAlert_numRows + Repeat1__numRows
%>

<%
    <!--SEND EMAILS TO STYLIST MATCHES-->
    While ((Repeat1__numRows <> 0) AND (NOT rsEmailAlert.EOF))
%>


<%
    Dim ObjSendMail
    Set ObjSendMail = CreateObject("CDO.Message")
   
<!--This section provides the configuration information for the remote SMTP server. -->
   
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/sendusing") = 2 <!--Send the message using the network -->(SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/smtpserver") ="mail.blackhair-salons.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/smtpusessl") = False <!--Use SSL for the connection (True or False) -->
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/smtpconnectiontimeout") = 60
 <!--If your server requires outgoing authentication uncomment the lines below and use a valid email address and password. -->
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/smtpauthenticate") = 1 <!--basic (clear-text)  authentication -->
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/sendusername") ="info@hair-salons.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration
/sendpassword") ="insonline"
   
ObjSendMail.Configuration.Fields.Update
   
<!--End remote SMTP server configuration section== -->
   
ObjSendMail.To = (rsEmailAlert.Fields.Item("A_Email").value)
ObjSendMail.Subject = "New Jobs Matching -" &" " & (rsEmailAlert.Fields.Item("S_Skills_Required").value) &"," &" " & (rsEmailAlert.Fields.Item("S_Skills_Location").value)
ObjSendMail.From = "info@hair-salons.com"
                       
Dim strBody
 
 strBody = strBody & "Welcome to the Jobs by Email Service" & vbCrLf & vbCrLf 
strBody = strBody & (rsEmailAlert.Fields.Item("S_Skills_Required").value) & vbCrLf ObjSendMail.TextBody = strBody
ObjSendMail.Send
   
Set ObjSendMail = Nothing
%>
           
 
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsEmailAlert.MoveNext()
Wend
%>
<%
Response.Write "Email Alerts Sent"
%>

<%
rsEmailAlert.Close()
%>

Any help would be great - Thanks

chsab420 Jun 25th, 2009 4:33 am
Re: Sending an Automatic Email
 
write this
strBody = "" before completing a loop
it will clear already whatever is in this so it will not repeat
try it and it will work

whisper_101 Jun 25th, 2009 5:05 am
Re: Sending an Automatic Email
 
Thankyou - works well.


All times are GMT -4. The time now is 3:57 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC