[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1397
  • Last Modified:

Adding multiple attachments to CDO.Message

Hi,

I'm looking up an image files in a database that a user selected in a checkbox in the previous page.  I attach these to the email in a loop.  The first image is sent fine, but sending multiple attachments causes this error:  "The specified protocol is unknown."

Here is where the files are attached:

****page 2 ********
dim arrImage()
redim arrImage(0)
dim str

for each str in split(request.form("chkImage"),",")
      arrImage(UBound(arrImage)) = str
      Redim Preserve arrImage(UBound(arrImage) + 1)
next

dim i
for i=0 to UBound(arrImage)-1
      MYCDOMAIL.AddAttachMent(arrImage(i))    'This is the line that causes error
next


***************************
The checkbox on page 1 is populated by the database:
<input type="checkbox" name="chkImage" value="<%= url %>">


where url is in the format:
\\Proxy\intranet\images\image1.jpg

I don't know if this format is causing the problem, I'm a little stumped as attaching just one image works fine, and CDO supports multiple attachments.

Thnx for your help.
0
LTY83
Asked:
LTY83
  • 10
  • 7
  • 2
1 Solution
 
peh803Commented:
Please try this syntax:
(from http://aspalliance.com/149)

msg.Attachments.Add (New MailAttachment(Server.MapPath("EMAIL1.ASPX")))

To send multiple attachments, just repeat the line Msg.Attachments.Add with the file that needs to be attached.

It may be specific to .NET, but then it may not....

Let me know if it works...

Thanks!
peh803
0
 
LTY83Author Commented:
Sorry...this is giving me an "Expected end of statement" error.  We only have ASP here, so can't use anything just for .NET
0
 
Marv-inCommented:
try to delimit the files with a semi colon
myMail.AddAttachment "test.txt;test2.txt"

or use cdonts if you can
Server.CreateObject("CDONTS.NewMail")


for i=0 to UBound(arrImage)-1
     MYCDOMAIL.AttachFile(arrImage(i))
next


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LTY83Author Commented:
tried delimiting as follows:

MYCDOMAIL.AddAttachment (arrImage(i) & ";")

and get this error:
"The system cannot find the file specified."  -- looking for a file with semicolon in name?

I tried something with cdonts before, but I'll give it another try with your example.  All the previous pages were done with CDO, so that's why I started there.
0
 
LTY83Author Commented:
Tried cdonts and it got stopped at the first line:

Set MYCDOMAIL = Server.CreateObject("CDONTS.NewMail")


error returned is "Invalid class string"
0
 
Marv-inCommented:
how big are the images? if they are big you might need to check the settings for the smtp server. there might be a limit on the size of the message.
0
 
LTY83Author Commented:
Still don't know exactly why the method above didn't work, but I solved it by taking another step before attaching.  I created another column on the table where I keep track of what was checked, then read from this table to send the attachments, rather than reading directly from the form:

      'attach flagged records from Images table
      sqlAttach = "SELECT * from Images where send=1"
      set rsAttach = conn.execute(sqlAttach)
      while not rsAttach.eof
            'attach to email
            MYCDOMAIL.AddAttachment(rsAttach("url"))
            rsAttach.movenext
      wend
0
 
peh803Commented:
Well, good work in solving the problem; anything else we can do for you on this one?

peh803
0
 
LTY83Author Commented:
As a matter of fact...

No problem now adding multiple attachments, but I am now having a problem updating the send column (to 1 if the user checked) on the Images table.


'Get selected images from last page (this works)
Dim selImages()
Redim selImages(0)
Dim str      
for each str in split(request.form("chkImage"),",")
  selImages(UBound(selImages)) = str
  Redim Preserve selImages(UBound(selImages) + 1)
next

'This is the loop I am using to update the table.  For some reason only the first record is
'being updated even when there is more than one value in selImages():
Dim i
for i=0 to UBound(selImages)-1
  sqlFlag = "UPDATE Images SET send=1 where url = '" & selImages(i) & "'"
  set rs = conn.execute(sqlFlag)
  'test:
  'response.write "<br>selImages("&i&")= " & selImages(i)
next


Thanks for any help with this.
0
 
peh803Commented:
I see you've already got test code in there to response.write the array values out, and it's commented out....try doing the same thing with sqlFlag in the loop and let us know what you get?

Thanks,
peh803
0
 
LTY83Author Commented:
Here's what I got -- syntax problem with single quotes around url in the sqlFlag query?

selImages(0)= http://127.0.0.1/images/DSTMessage002lowres.jpg
UPDATE Images SET send=1 where url= 'http://127.0.0.1/images/DSTMessage002lowres.jpg'

selImages(1)= http://127.0.0.1/images/Flagstone P7130020 side.jpg
UPDATE Images SET send=1 where url= ' http://127.0.0.1/images/Flagstone P7130020 side.jpg'

selImages(2)= http://127.0.0.1/images/Design_Stone/flagstone/Greyhawk g2.jpg
UPDATE Images SET send=1 where url= ' http://127.0.0.1/images/Greyhawk g2.jpg'

0
 
LTY83Author Commented:
BTW, the query under selImages(2) is referencing the correct url.  I just cut out some of the folders in the address to make it easier to read, and didn't catch that one.

Thanks,
LTY
0
 
peh803Commented:
Okay, and the problem you're having is that it just doesn't update the appropriate fields?  The statements execute successfully?  Or, rather, do you actually see errors when the statements are run?

Thanks,
peh803
0
 
LTY83Author Commented:
OK, noticed that there is a space put in all the selImages values after the first one.  Am I splitting this wrong?

Thanks
0
 
peh803Commented:
not necessarily. ... but that probably is the problem.  

you can fix it by doing this:

-------old code-------
sqlFlag = "UPDATE Images SET send=1 where url = '" & selImages(i) & "'"
-------old code-------
-------new code-------
sqlFlag = "UPDATE Images SET send=1 where url = '" & trim(selImages(i)) & "'"
-------new code-------

HTH!
peh803
0
 
LTY83Author Commented:
Only the first sql statement runs as I would have expected.  I don't get any errors, but the next statements don't update.  I *think* it may just be that whitespace in those statements.
0
 
peh803Commented:
Glad to help you resolve your problem!  

Thanks, as always, for using E.E.!

Regards,
peh803
0
 
LTY83Author Commented:
That little change did it!

I'm relatively new to all this and really appreciate your help.  Thanks!
0
 
peh803Commented:
Again, glad to help!!

Hope to talk to you again,
peh803
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now