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

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

Hey ive tried this code and several others too and it doesnt seem to work...
Is there nething else besides the code which i need to do to get it to work?
Appreciate the help...

This question has already been answered. Start a new discussion instead.