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
.Update
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
err.Clear
End If
End If
Next

.Send
End With
END SUB

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

'Cleanup
Set ObjCDO = Nothing
Set iConf = Nothing
Set Flds = Nothing


Response.Write "Email Sent"
END IF
%>

HTML Page
---------

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

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
filename/path?

--
Tom Kaminski IIS MVP
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/ , scripts, and utilities for running IIS
http://www.yqcomputer.com/