How to attach multiple attachments using ASP CDO

How to attach multiple attachments using ASP CDO

Post by tabonn » Wed, 25 Aug 2004 15:57:46

Hi, All

I try to attach multiple attachments in an email using ASP CDO.
Sending email part is running fine, but there are no attachments in
it. Please tell me what do you observe.

My idea is: When I select the required files in the check box inside
HTML page, it will pass all the selected value to ASP page. Then, the
ASP page will run the sendmail subroutine in order to send an email
and the attachments.

Here is my code:

ASP Page
SUB sendmail( toWho, Subject, Body )
Dim objCDO
Dim iConf
Dim Flds

Const cdoSendUsingPort = 2

On Error Resume Next

Set objCDO = Server.CreateObject("CDO.Message")
Set iConf = Server.CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "newserver"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
End With

'Set objCDO.Configuration = iConf

With objCDO
Set .Configuration = iConf
.From = " XXXX@XXXXX.COM "
.To = toWho
.Subject = Subject
.TextBody = Body

courseOutline = Request.Form( "Bus" )
courseOutline = Split( courseOutline, "," )

For Each member in courseOutline
If courseOutline <> "" Then
.AddAttachment Server.MapPath(member)
If err.number <> 0 Then
.TextBody = .TextBody & vbCrlf & vbCrlf & _
"Unable to attach file " & member & "." & vbCrlf & Err.Description
End If
End If

End With

toWho = TRIM( Request.Form("To") )
Subject = TRIM( Request.Form("Subject") )
Body = TRIM( Request.Form("Body") )
IF toWho <> "" THEN
sendMail toWho, Subject, Body

Set ObjCDO = Nothing
Set iConf = Nothing
Set Flds = Nothing

Response.Write "Email Sent"


<form action="myMail.asp" method="post">
MS Outlook
<input type="checkbox" value="outlook.pdf" name="Bus" />
MS Word
<input type="checkbox" value="word.pdf" name="Bus" />
MS Excel
<input type="checkbox" value="excel.pdf" name="Bus" />
<input type="submit" value="Submit" name="Submit" />

Thank you.

How to attach multiple attachments using ASP CDO

Post by Tom Kamins » Wed, 25 Aug 2004 22:04:15

Where do you set the value of "member"? Does it have the correct

Tom Kaminski IIS MVP , scripts, and utilities for running IIS