<%
this is coded by nick@stilwell.ws
using the upload.asp example from asp101.com
and combining it with the mail object to allow
you upload a pic from your pc and email to anyone anywhere
at anytime maybe it should be called martini mail
response.buffer = true
function buildupload(requestbin)
get the boundary
posbeg = 1
posend = instrb(posbeg,requestbin,getbytestring(chr(13)))
boundary = midb(requestbin,posbeg,posend-posbeg)
boundarypos = instrb(1,requestbin,boundary)
get all data inside the boundaries
do until (boundarypos=instrb(requestbin,boundary & getbytestring("–")))
members variable of objects are put in a dictionary object
dim uploadcontrol
set uploadcontrol = createobject("scripting.dictionary")
get an object name
pos = instrb(boundarypos,requestbin,getbytestring("content-disposition"))
pos = instrb(pos,requestbin,getbytestring("name="))
posbeg = pos+6
posend = instrb(posbeg,requestbin,getbytestring(chr(34)))
name = getstring(midb(requestbin,posbeg,posend-posbeg))
posfile = instrb(boundarypos,requestbin,getbytestring("filename="))
posbound = instrb(posend,requestbin,boundary)
test if object is of file type
if posfile<>0 and (posfile<posbound) then
get filename, content-type and content of file
posbeg = posfile + 10
posend = instrb(posbeg,requestbin,getbytestring(chr(34)))
filename = getstring(midb(requestbin,posbeg,posend-posbeg))
add filename to dictionary object
uploadcontrol.add "filename", filename
pos = instrb(posend,requestbin,getbytestring("content-type:"))
posbeg = pos+14
posend = instrb(posbeg,requestbin,getbytestring(chr(13)))
add content-type to dictionary object
contenttype = getstring(midb(requestbin,posbeg,posend-posbeg))
uploadcontrol.add "contenttype",contenttype
get content of object
posbeg = posend+4
posend = instrb(posbeg,requestbin,boundary)-2
value = midb(requestbin,posbeg,posend-posbeg)
else
get content of object
pos = instrb(pos,requestbin,getbytestring(chr(13)))
posbeg = pos+4
posend = instrb(posbeg,requestbin,boundary)-2
value = getstring(midb(requestbin,posbeg,posend-posbeg))
end if
uploadcontrol.add "value" , value
uploadrequest.add name, uploadcontrol
boundarypos=instrb(boundarypos+lenb(boundary),requestbin,boundary)
loop
end function
function getbytestring(stringstr)
for i = 1 to len(stringstr)
char = mid(stringstr,i,1)
getbytestring = getbytestring & chrb(ascb(char))
next
end function
function getstring(stringbin)
getstring =""
for intcount = 1 to lenb(stringbin)
getstring = getstring & chr(ascb(midb(stringbin,intcount,1)))
next
end function
if request("action")="1" then
response.clear
bytecount = request.totalbytes
requestbin = request.binaryread(bytecount)
set uploadrequest = createobject("scripting.dictionary")
buildupload(requestbin)
if uploadrequest.item("blob").item("value") <> "" then
contenttype = uploadrequest.item("blob").item("contenttype")
filepathname = uploadrequest.item("blob").item("filename")
filename = right(filepathname,len(filepathname)-instrrev(filepathname,"\"))
foldername = uploadrequest.item("where").item("value")
response.write "foldername: " & foldername & "<br>"
path = mid(request.servervariables("path_translated"), 1, len(request.servervariables
("path_translated")) – len(request.servervariables("path_info"))) & "\"
response.write "path:" & path & "<br>"
tofolder = path & "\" & foldername
value = uploadrequest.item("blob").item("value")
filename = tofolder & "\" & filename
set myfileobject = server.createobject("scripting.filesystemobject")
set objfile = myfileobject.createtextfile(filename)
response.write "saved path: " & filename
for i = 1 to lenb(value)
objfile.write chr(ascb(midb(value,i,1)))
next
objfile.close
set objfile = nothing
set myfileobject = nothing
end if
ge the other form elements now
mysubject = uploadrequest.item("mysubject").item("value")
myto = uploadrequest.item("myto").item("value")
mytext = uploadrequest.item("mytext").item("value")
myfrom = uploadrequest.item("myfrom").item("value")
set uploadrequest = nothing
set objcdomail = server.createobject("cdonts.newmail")
objcdomail.from = myfrom
objcdomail.to = myto
objcdomail.bodyformat = 0
objcdomail.mailformat = 0
objcdomail.subject = mysubject
objcdomail.body = mytext
heres an if statement to chk for an attachment
i am sure theres another way but this does the job fine
if len(filename) > 5 then
objcdomail.attachfile filename,nikfile
end if
objcdomail.send
set objcdomail = nothing
response.write "your mail has been sent"
end if%>
<html>
<head>
<title>anon mail</title>
<!–
this is coded by nick@stilwell.ws
using the upload.asp example from asp101.com
and combining it with the mail object to allow
you upload a pic from your pc and email to anyone anywhere
at anytime maybe it should be called martini mail
–>
<style>
.text { font-family: verdana,arial;
color: black;
font-size: 10pt
}
</style>
</head>
<body><form method="post" enctype="multipart/form-data" action="mailattachment.asp?action=1"
name="mailform" id="mailform">
<table border="0" align="center" width="350">
<tr>
<td class="text" colspan="2">
<h3>send an email to anyone with an attachment</h3>
</td>
</tr>
<tr>
<tr>
<td class="text" align="left">from</td>
<td class="text" align="right"><input class="text" type=text name=myfrom
size="30"></td>
</tr>
<tr>
<td class="text" align="left">to:</td>
<td align="right"><input class="text" name="myto" size="30"></td>
</tr>
<tr>
<td class="text" align="left">subject:</td>
<td align="right"><input class="text" type=text name=mysubject size="30"></td>
</tr>
<tr>
<td class="text" colspan="2">enter your email text below</td>
</tr>
<tr>
<td class="text" colspan="2" align="right"><textarea class="text" rows="7"
name="mytext" cols="65"></textarea></td>
</tr>
<tr>
<td colspan="2" class="text" align="center">
attach a file: <input type="file" name="blob" value>
<input type="hidden" name="where" value="images">
<!– change the value of this hidden field to change the directory of
where uploads are stored–>
</td>
</tr>
<tr>
<td colspan="2" class="text">
<input class="text" type="submit" value="send it!" id=submit1
name=submit1></td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
