Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > CDO message attach files

Reply
Thread Tools

CDO message attach files

 
 
sallysmedly@yahoo.com
Guest
Posts: n/a
 
      06-18-2007
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.mydomai n.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 Removed)"
objMail.To = "(E-Mail 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>

 
Reply With Quote
 
 
 
 
David Morgan
Guest
Posts: n/a
 
      06-28-2007
http://www.4guysfromrolla.com/webtech/112298-1.shtml

Is the uploaded file in the same folder as the ASP page? It is unlikely
that Server.MapPath should be used with ExtractFilename.

Just attached based on the full folder name and file name of the uploaded
file.



<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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.mydomai n.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 Removed)"
> objMail.To = "(E-Mail 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>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there any shortcut for "Debug > Attach > Attach to aspnet_wp.exe"? Warren Tang ASP .Net 1 09-17-2008 03:46 PM
attach agent to applet running in firefox (attach api) craiget@gmail.com Java 0 06-14-2007 12:28 AM
what is ("http://schemas.microsoft.com/cdo/configuration/sendusing") doing in CDO uofs76@yahoo.com ASP General 0 02-07-2007 01:09 PM
Can't attach attachments in email using ASP CDO tabonni ASP General 15 09-01-2004 12:58 AM
CDO for Windows 2000 vs CDO for Exchange 2000 ASP .Net 2 07-11-2003 12:31 PM



Advertisments