CDO message attach files

S

sallysmedly

Hi,

I have a page where a user can browse for and attach 2 files to an
email.

The email works fine when I try to send a selected file from the
server, but I have added in some script so that it sends the files the
user has selected, but this part won't work.

Any suggestions would be much appreciated.

emailtest.asp

<%
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")

'Configuration:
objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort

objConfig.Fields(cdoSMTPServer)="auth.smtp.mydomain.co.uk"
objConfig.Fields(cdoSMTPServerPort)=25
objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
objConfig.Fields(cdoSendUserName) = "username"
objConfig.Fields(cdoSendPassword) = "password"

'Update configuration
objConfig.Fields.Update
Set objMail.Configuration = objConfig

objMail.From ="(e-mail address removed)"
objMail.To = "(e-mail address removed)"
objMail.Subject = "You have a new message"
objMail.TextBody = "You have a entry from "


'this bit doesn't work
for each file in Upload.Files
fn=File.ExtractFilename
objMail.AddAttachment Server.MapPath(fn),fn
next
'end of bit not working

'this does work, but only attaches a fixed file, rather than user
selected file
'objMail.AddAttachment "http://www.mydomian.com/code.htm"
objMail.Send

If Err.Number = 0 Then
Response.Write("Mail sent!")
Else
Response.Write("Error sending mail. Code: " & Err.Number)
Err.Clear
End If
Set objMail=Nothing
Set objConfig=Nothing
%>


form email:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>

<body>
<form action="emailtest.asp" method="post" enctype="multipart/form-
data" name="form1">
<p>
<input name="file1" type="file" id="file1">
</p>
<p>
<input type="file" name="file2" id="file2">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top