Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Send email with MULTIPLE ATTACHMENTS using CDO

Posted on 2004-10-21
Medium Priority
Last Modified: 2012-05-05
I would like to have an ASP page that can send email with multiple attachment. Below is my code with 1 attachment and it is working.

SendMsg Mailto, MailCC, MailBCC, MailFrom, MailSub, MsgBody,"C:\\InetPub\wwwroot\"&mid(File.Path,35,len(File.Path))"
Question by:CochiseCounty
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 15

Accepted Solution

justinbillig earned 500 total points
ID: 12372329
your going to have to change your sendmsg subroutine to accept an array of filenames, then loop through the file names and add the attacments.

Could you post your sendmsg subroutine

Assisted Solution

mistyrae earned 500 total points
ID: 12383891

If you just modify your routine, as I have given an example of below, to check to see whether the attachment argument is a string or an array, you can allow multiple attachments or single attachments, without breaking any code that is only using single.

Here is my sample SendMsg subroutine:

Sub SendMsg (to, cc, bcc, from, subj, body, attach)
      Dim oMail
      Dim oFs
      Dim sAttach

      Set oMail = Server.CreateObject("CDONTS.NewMail")
      oMail.To = to
      If cc <> "" Then
            oMail.CC = cc
      End If
      If bcc <> "" Then
            oMail.BCC = bcc
      End If

      oMail.From = from
      If subj = "" Then
            oMail.Subject = "[no subject]"
            oMail.Subject = subj
      End If

      oMail.Body = body

      Set oFs = Server.CreateObject("Scripting.FileSystemObject")
      On Error Resume Next
      If IsArray(Attach) Then
            For i = 0 To Ubound(Attach)
                  sAttach = ""
                  If oFs.FileExists(attach(i)) Then
                        sAttach = attach(i)
                  ElseIf oFs.FileExists(Server.MapPath(attach(i))) Then
                        sAttach = Server.MapPath(attach(i))
                  End If
                  If sAttach <> "" Then
                        oMail.AttachFile sAttach
                  End If
            sAttach = ""
            If attach <> "" Then
                  If oFs.FileExists(attach) Then
                        sAttach = attach
                  ElseIf oFs.FileExists(Server.MapPath(attach)) Then
                        sAttach = Server.MapPath(attach)
                  End If

                  If sAttach <> "" Then
                        oMail.AttachFile sAttach
                  End If
            End If
      End If

      On Error GoTo 0
      Set oFs = Nothing


      Set oMail = Nothing
End Sub

- misty

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question