Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Local Attachments in ASP 2

Status
Not open for further replies.

cmv131

MIS
Feb 16, 2005
158
US
Is there a way to attach a local file (submitted on a form) to an Email in ASP. All references I have seen point towards no, but looking for a few more opinions.

Using Win 2k3 server, we have a web form we want to email a user when ever submitted. When the user puts an attachment, we want to to be on the email. All the resources I have seen say that this file has to be on the server.

Is there a way to do it from a local file?

Set objCDOMail = Server.CreateObject("CDO.Message") is the email we are using. Any help is appreciated.

Thanks
Chris
 
try something like this:

objCDOSYSMail.Attachfile server.MapPath("yourfile")

-DNG
 
The problem with those is that they are looking for the directory on the server...Correct?

If I have a local file I want to attach, will this work?
 
sorry didnt understand your question well...

"if i have a local file"...do you mean local to client's machine...

please explain more on what actually you are trying to do...

-DNG
 
yes. I mean local to a client machine...

If I go to this website, and want to attach one of my files (doc or screen shot or pdf etc...) for reference so that the person who recieves the email can use it.
 
still didnt get you but here is the case...

if i am a client and i have a email form with all the necessary fields and also an attachment field...i can fill all the required fields and i can upload the file from my local machine...on the other hand you being at the server will receive email and the file that i attached will be saved on your server...


but if you want to browse for a file which is on the server from the client side...you cannot do that...

hope that makes sense...

-DNG
 
Alright. That makes some more sense.

So if I want to upload a file from my local machine I can use
ObjSendMail.AddAttachment "c:\myweb\somefile.jpg"

Can I then use

ObjSendMail.AddAttachment Request.Form("attach")

or is there a different (or better way) to pull in the path from the form being submitted? (Doing it like above give me a page cannot be displayed)
 
So if I want to upload a file from my local machine I can use
ObjSendMail.AddAttachment "c:\myweb\somefile.jpg"

[blue]YES[/blue]


Can I then use

ObjSendMail.AddAttachment Request.Form("attach")

[red]???[/red]

why and where are you trying to use this...you are trying to refer one form field content into the other even without the form getting processed...

-DNG
 
sorry i misread your previous post...

yes you can refer the path from your form field...


-DNG
 
Let me try 1 more time to explain what we are trying to do (in a little more detai).

We have a website with an HTML webform which submitts to an ASP confirmation page. The ASP page is (obviously) where the email gets setup using things like

objCDOMail.From = Request.Form("email")

to pull in the data from the HTML form which was submitted to this ASP page. This data is then sent from the server to an individual via email. All this works as designed, except when we try to code it to bring in the attachment.
Request.Form("attach") contains the path on the client machine where the file is being sent from.

The schema would look similar to this

User --> Server (Website and form) --> Recipient

I need a way to get the file of the Users machine, attached to the EDO email message and delivered to the Recipient.

Also, since I need to specify the attachment path, I need a way to use the data from Request.Form("attach") in the attachment function or method or whatever it is.

Let me know if that makes any more sense
 
Also if I do

ObjCDOMail.Attachfile server.MapPath(Request.Form("attach"))

or

ObjCDOMail.AddAttachment Request.Form("attach")

I get a page cannot be displayed error. This only occurs when these lines are active in the code, so there is either asyntax error in them, or it is not possible to call the funtion like that
 
ok here are the stages...

1. User

Submitted his email using the form and also attached a file from his local machine.


2. SERVER

here you do all the asp processing and collect all the information submitted by the user...so now you have user's email address and the file attached by him saved to your server...IS THIS RIGHT....

3. Recipient...i am not sure who this is...but lets say there is another user who wants to see the file attached by the user....

then you need to provide him a file download application so that he can refer to the users email address or id and get the needed file and save on his machine...

did i get that right...

-DNG
 
hmmm,

I've always uploaded the file first to a temp directory, put that location/file name into a variable

then use the variable for the email attachment location.

end it up with deleting the file uploaded.

"Ever stop to think, and forget to start again?"

Stuart
A+, Net+
 
also it should be:

ObjCDOMail.AddAttachment """"&Request.Form("attach")&""""

-DNG
 
First. Thanks for your willingness to try to sort through this

2nd, that is kind of right


All I really want to do is attach a file from a client machine to an email that gets sent to recipient X.

Lets say I access
this webform has an attachment input setup like this:
input type="file" name="attach"

I click submit. This sends me to
Here the email gets setup through

Set objCDOMail = Server.CreateObject("CDO.Message")

with items like

objCDOMail.From = Request.Form("email")

to setup the email from the submitted form (with the other items in place obviously). I want to add to this email the attachment through either of the 2 methods you mentioned above using

Request.Form("attach")

to reference where the file should be attached from
 
Hi,
I do not think any ASP code can read anything from the client accessing it, since it is a server-side process and does not really 'know' anything about the client PC ( well,it 'knows' its IP address and maybe some other stuff, but certainly not drive letters or paths).


Perhaps I'm wrong - but then, there would be many security issues involved in letting a web site access your local system's files..




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
cmv131, i understood your requirement...here is the thing

cmv131 said:
to setup the email from the submitted form (with the other items in place obviously). I want to add to this email the attachment through either of the 2 methods you mentioned above using

in whatever you said above you are looking at two stages...

collecting and storing the file and then sending the email to respective recipient...

but when user attaches a file you HAVE TO SAVE THE FILE ON YOUR SERVER....so now the path of this file attached by the user will be...something like...c:/inetpub/
now you cannot refer this path to the recipient because he is just on another client machine and cannot access this file which is on your server...

-DNG
 
May be you could first store all the information sent by the user in a database...

UserName, RecipientName, UserEmail, RecipientEmail, UserFileName

example datat:

cmv, dng , cmv@blah.com, dng@blah.com, cmvfile.doc

now collecting everything is very easy...just gather the form variables using Request.Form, except the last one...

since it is a file...you need to first save it(lets say you are always saving the file at c:/inetpub/
then whenever there is an insert in your database...you fire a email trigger that sends email to the recipient with the file link as
c:/inetpub/ and make the recipient download the file to his local machine from your server...

does this process makes any sense to you...

-DNG
 
Thanks for all the help.

The answer I needed was "but when user attaches a file you HAVE TO SAVE THE FILE ON YOUR SERVER"

I appreciate the effort, and I will add to the script to upload the file to the server.

Thanks again
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top