Avatar of Mark Drelinger
Mark Drelinger
Flag for United States of America asked on

Trouble sending an email with multiple attachments using CDONTS

I am trying to send an email with multiple attachments using CDONTS.
The code below sends the email, but never attaches anything.
I feel like I've got a vb script errror where I scroll through the record set rsEQUIPInvoicesAttach, which contains 2 records.
If I take that loop out of my code, I can manually create an email with multiple attachments, so I'm confident my CDO syntax is correct.

<% if (cStr(Request("Submit")) <> "") Then
Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = Request("varFrom")
objCDO.To = Request("varTo")
objCDO.Subject = "Invoices from Schmidt Equipment"
objCDO.Body = "Invoices from Schmidt Equipment"

While ((Repeat6__numRows <> 0) AND (NOT rsEQUIPInvoicesAttach.EOF))
           objCDO.AttachFile "C:\test.txt"
          Repeat6__index=Repeat6__index+1
              Repeat6__numRows=Repeat6__numRows-1
        rsEQUIPInvoicesAttach.MoveNext
       Wend        
            
objCDO.Send()
Set objCDO = Nothing
Response.Redirect("/menu.asp")

End If
%>
VB Script

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
Mark Drelinger

ASKER
also, this is further up the page:
<%
Dim Repeat6__numRows
Dim Repeat6__index

Repeat6__numRows = -1
Repeat6__index = 0
rsEQUIPInvoicesAttach_numRows = rsEQUIPInvoicesAttach_numRows + Repeat6__numRows
%>
Mark Drelinger

ASKER
Also tried this but got "Either BOF or EOF is True, or the current record has been deleted". Recordset has two records.

<% if (cStr(Request("Submit")) <> "") Then
Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.From = Request("varFrom")
objCDO.To = Request("varTo")
objCDO.Subject = "Invoices from Schmidt Equipment"
objCDO.Body = "Invoices from Schmidt Equipment"

Do until Not rsEQUIPInvoices.EOF
     objCDO.AttachFile "C:\test.txt"
       rsEQUIPInvoices.MoveNext
Loop    
            
objCDO.Send()
Set objCDO = Nothing
Response.Redirect("/menu.asp")

End If
%>
ASKER CERTIFIED SOLUTION
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mark Drelinger

ASKER
I think the issue was more the placement of my code within the page - when it ran that routine, the recordset was null.  Your comment was helpful none the less. Regards, Mark Drelinger
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
RobSampson

OK cool.  I couldn't see where Repeat6_numRows was being set as a positive number, so just wanted to point that out.

Good to see you have it sorted now.

Regards,

Rob.