views:

431

answers:

3

Hi Guys,

Ive got abit of a problem ive got an email web form that send the input to an email address but what I now need is a file input field were the user can also send an image as an attachment.

So contact name, logo (attachment).

Ive been told in order to send the attachment it needs to be saved in a folder on my hosting before it can be sent. Ive spoken to the hosting company and they dont have anything in place to make this easier such as aspupload.

In the form name="contactname" and name="logo" I have a folder in the root directory called logos (this asp page also exists in the root directory)

Man I hope someone can help me spent along time looking for answers

Dim contactname, logo

contactname = request.form("contactname")
If request("contactname") <> "" THEN
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Form"
myMail.From="web@email"
myMail.To="web@email"
myMail.HTMLBody = "" & contactname & ""
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay.host"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
+1  A: 

Can't you just use one of the following, depending on the format of the location you get from the input field? You shouldn't have to save it to the server.

<% 
' ... 

myMail.AddAttachment Server.MapPath("file1.txt") 
myMail.AddAttachment "d:\file2.txt" 
myMail.AddAttachment "file://d:\file3.txt" 

' ...
%>
schmimd04
From the server you won't have access to the users file/directory specified in the input field. You would need to grab the content from the multipart form post, serialize to a file on the server, and then `AddAttachment` using the path to the temp directory/file (and then delete that file off the server after sending the email)
Mads Hansen
Couldn't you grab the file stream from the file upload component and and add that as the attachment? I'm not sure if you can do that in classic ASP, but pretty sure it's possible in .Net
schmimd04
Guys any solutions??
apg1985
A: 

erm yeah I could use one of the above if the file was stored already but it not. The file is coming off the end users pc.

So they click browser in the form and navigate to the file on there pc. Which I think then needs to be saved to a file on my hosting then file location inserted kinda like you have done in order for it to be sent.

apg1985
+1  A: 

You need to use a file input control. The basic idea is that you declare your form like this:

<form method="POST" action="YourScript.asp" enctype="multipart/form-data">
<input name="ContactName" type="text" size="50">
<input name="LogoFile" type="file">
<input type="submit" value="Send">
</form>

YourScript.asp should then use an ASP Upload control to store the uploaded file somewhere on the server, and then use the AddAttachment method of CDOSYS.

Note: When using this upload component, the normal Request.Form is no longer available (due to Response.BinaryRead being called). You can get to the ContactName value by using the Fields collection of this upload control instead.

Such an ASP Upload control can be found here:

http://www.asp101.com/articles/jacob/scriptupload.asp

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=7361&amp;lngWId=4

thomask