Send email with MULTIPLE ATTACHMENTS using CDO

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))"
CochiseCountyAsked:
Who is Participating?
 
justinbilligConnect With a Mentor Commented:
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
0
 
mistyraeConnect With a Mentor Commented:
Hi,

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]"
      Else
            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
            Next
      Else
            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

      oMail.Send

      Set oMail = Nothing
End Sub
%>


- misty
0
All Courses

From novice to tech pro — start learning today.