Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > ASP CDO
|
ASP CDO As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP CDO section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2005, 12:56 PM
Authorized User
 
Join Date: Jun 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to send MULTIPLE ATTACHMENTS with CDONTS?

Hello everyone,

I tried to GOOGLE a straight answer to my problem but have come up with nada.

All I want to do is attach more than one file to my email messages, via CDONTS in my ASP Code (is that so wrong?).

EX:
CDO_NEWMAIL.AttachFile Server.MapPath("MyFile1.pdf")

This works.

However:

CDO_NEWMAIL.AttachFile Server.MapPath("MyFile1.pdf",MyFile2.pdf")

and other variations just cause errors.

HELP!!!!

Thank you to anyone who can help,


Susan :)
__________________
Susan :)
 
Old May 3rd, 2005, 01:03 PM
Authorized User
 
Join Date: Jun 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh for Pete's sake ... I already answered my own question.

For anyone who wants to know, this is what worked:
<%
CDO_NEW.To = "[email protected]"
CDO_NEW.Subject = "Multiple attachments"
CDO_NEW.Body = "This email has more than one attachment."
CDO_NEW.AttachFile(Server.MapPath("MyFile1.pdf"))
CDO_NEW.AttachFile(Server.MapPath("MyFile2.pdf"))
CDO_NEW.Send
%>

Now all I have to do is figure out a way to make multiple attachments *dynamically*, based on the records in my database, but at least I know the syntax ... and that's half the battle!

Giving self congratulatory pat on back,



Susan :)
 
Old May 3rd, 2005, 04:23 PM
Authorized User
 
Join Date: Jun 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And now I've successfully programmed the CDONTS to *dynamically* attach multiple files!! Mind you, I leaned heavily on a thread I found here:
http://forums.aspfree.com/archive/t-...le-with-CDONTS

Without further ado:

<%
'|| Globally declare:
'|| 1) my array of files
'|| 2) the string variable will fill it.
Dim arrFiles,myArray

'||------------------------------------
'|| Begin SendMail Procedure
'||------------------------------------
Sub SendMail(iNumber) '|| iNumber is just a unique value being
                      '|| pulled from our database, like an OrderID
                      '|| or CustomerID, etc.

Dim CDO_MAIL,iArrCount


BuildAttachment '|| Call "BuildAttachment" Function;
                              '|| This will loop through recordset
                              '|| and find files to put in array.

arrFiles = Split(myArray,",") '|| Fill arrFiles array with string
                              '|| from BuildAttachment function.

Set CDO_MAIL = Server.CreateObject("CDONTS.NewMail")
CDO_MAIL.To = "[email protected]"
CDO_MAIL.From = "[email protected]"
CDO_MAIL.Subject = "There are several files attached to this note."
CDO_MAIL.Body = "ATTENTION! Files attached!"

For iArrCount = LBound(arrFiles) To UBound(arrFiles)
    CDO_MAIL.AttachFile(Server.MapPath(arrFiles(iArrCo unt)))
Next
CDO_MAIL.Send
End Sub

'||---------------------------------------------
'|| Begin BuildAttachment Function
'||---------------------------------------------
Function BuildAttachment(iNumber)
  Dim cnx, rsFiles, myFile, intFileNum

  '|| BUILD A SELECT STATEMENT HERE TO LOOP THROUGH
  '|| DATABASE, ie, "SELECT * FROM v_Records
  '|| "WHERE numID = " & iNumber
  Set rsFiles = cnx.ExecuteQuery()

  intFileNum = 0 '|| This counts the number of times we are
                  '|| going through the database and
                  '|| helps to keep attachment names unique.

  Do While Not rsFiles.EOF
     intFileNum = intFileNum + 1
     myFile = rsFiles("myValue") & "_attchmt" & intFileNum & ".pdf"

    '|| If there is more than one file, than make sure there
    '|| are commas separating the names in the array.
    '|| Otherwise, just fill it with the one name, no commas needed.
     If intFileNum > 1 Then
          myArray = myArray & "," & myFile
     Else
          myArray = myFile
     End If

  rsFiles.MoveNext
  Loop

End Function
%>

That's pretty much all there was to it. Now all I need is a way to clean out my folder after saving all those pdf files to it ... that should be the easy part of this puzzle!

Hoping this helps someone,

Susan :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send attachments through a SMTP server Pawan Sangal Perl 3 December 7th, 2006 10:37 AM
Using CDONTS to send SQL server errors kevorkian SQL Server ASP 1 April 22nd, 2005 06:15 AM
Send Emails and Attachments. mistry_bhavin General .NET 2 August 11th, 2004 10:05 AM
CDONTS send mail for Earthlink egerdj Wrox Book Feedback 1 February 17th, 2004 05:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.