We often explore the use of ASP, and do not use other build can achieve file upload, so as to develop a mail system to support mail attachments, the answer is yes.
The following is the page to send the mail, the mail account number is the employee, the assumption is 5 digits, sendmail.asp of course, after the legal landing will be able to see
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<link rel= "stylesheet" type= "Text/css" href= "/css/forum". CSS ">
<style type=text/css>
!--
input {font-size:9pt; color: #0011dd; Background-color: #e9e9f9; padding-top:0px}
Select {font-size:9pt; color: #0011dd; Background-color: #e9e9f9; padding-top:0px}
textarea {font-size:9pt; color: #0011dd; Background-color: #e9e9f9; padding-top:0px}
-->
</style>
<title> Mail system </title> <body bgcolor= "#FEF7ED" >
<script language= "JavaScript" >
<%
If session ("myID") = "" or Len (Session ("myID")) <> 5 Then
Response.Write "window.open (' nolog.asp ', target= ' _top ');"
End If
%>
function Check (theform)
{
if (theform.geterempl.value== ')
{
Alert (' Please enter the recipient! ');
Theform.geterempl.focus ();
return false;
}
if (theform.emailtitle.value== ')
{
Alert (' Please enter a theme! ');
Theform.emailtitle.focus ();
return false;
}
if (theform.emailtitle.value.length>200)
{
Alert (' Subject please less than 200 bytes ');
Theform.emailtitle.focus ();
return false;
}
if (theform.body.value.length>15*1024)
{
Alert (' Text please less than 16K ');
Theform.body.focus ();
return false;
}
if (theform.emailshowname.value.length>1024)
{
Alert (' sign please less than 1K ');
Theform.emailshowname.focus ();
return false;
}
}
</script>
<%
Meth=request.querystring ("meth")
If Meth=1 Then
Geterempl=trim (Request.QueryString ("Geterempl"))
Emailtitle=trim (Request.QueryString ("Emailtitle"))
ElseIf meth=2 Then
Mailid=trim (Request.QueryString ("Mailid"))
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "dsn=; uid=; Pwd= "
Dsnpath= "dsn=; uid=; Pwd= "
Set Rs=server.createobject ("Adodb.recordset")
Selectnew= "SELECT * from T_mail where (Geterempl like '%" &session ("myID") & "%" or deleempl like '% "&session (" myID ") &"% ' or receempl like '% "&session (" myID ") &"% ") and (not deleverempl like '% ' &session (" myID ") & "%")) and mailid= ' "&mailid&" "
Rs.Open selectnew,dsnpath,3,3
If Rs.bof or rs.eof then
%>
<script language= "JavaScript" >
Alert ("You do not have permission to view this message!") ");
Window.history.back ();
</script>
<%
Response.End
Else
Body=rs ("Body")
Emailtitle=rs ("Emailtitle")
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
End If
End If
%>
<form name= "Upload_file" action= "loadmail.asp" Method=post enctype= "Multipart/form-data"
<table width= "100%" border= "0" cellspacing= "2" cellpadding= "2"
<tr>
<TD width= "11%" >
<div align= "right" to Sender: </div>
</td>
<TD width= "89%" >
<input type= "hidden" name= "Senderempl" value= "<%=session" ("myID")%> ""
<%=session ("myID")%> </td>
</tr>
<tr>
<TD width= "11%" >
<div align= "Right" recipients: </div>
</td>
<TD width= "89%" >
<input type= "text" name= "Geterempl" size= "value=" "<%=geterempl%>"
<input type= "checkbox" Name= "EmailLevel" value= "1" style= "Background-color: #FEF7ED"
Emergency letter </td>
</tr>
<tr>
<TD width= "11%" valign= "top" > </td>
<TD width= "89%", when you send multiple people, you can use the "<font color=" #9999FF ">| </font>" to separate, for example: <font color= "#3399FF" >01234|01235|01236 </font>, The first and last one does not need "<font color=" #9999FF ">| </font>"
<font color= "#FF0000" > new features </font>: You can send the letter directly to you set the <a Href= "group.asp" > a user </a>, sent in the form of: GR: Group number, such as <font color= "#0099FF" >gr:001 </font> </td>
</tr>
<tr>
<TD width= "11%" >
<div align= "right" > </div>
</td>
<TD width= "89%" >
<input type= "checkbox" Name= "Receempl" value= "1" style= "Background-color: #FEF7ED"
Save a copy to Favorites [<font color= "#3399FF" to select this item, the message is sent to each other's mailbox and sent to your favorites </font>] </td>
</tr>
<tr>
<TD width= "11%" valign= "top" > </td>
<TD width= "89%" > </td>
</tr>
<tr>
<TD width= "11%" align= "right" theme: </td>
<TD width= "89%" >
<input type= "text" name= "Emailtitle" size= "value=" "<%=emailtitle%>"
</td>
</tr>
<tr>
<TD width= "11%" valign= "Top"
<div align= "Right", Text: </div>
</td>
<TD width= "89%" >
<textarea name=body rows=8 cols=60> <%=body%> </TEXTAREA>
</td>
</tr>
<tr>
<TD width= "11%" valign= "Top"
<div align= "Right" signature: </div>
</td>
<TD width= "89%" >
<textarea name= "Emailshowname" cols= "rows=" "6" ><%=application (Session ("myID") & "_name")%> </textarea>
</td>
</tr>
<tr>
<TD width= "11%" >
<div align= "Right"
<input type=hidden name= "Fileuploadstart"
Annex 1: </div>
</td>
<TD width= "89%" >
<input type= "File" Name= "file_up" size= "50"
</td>
</tr>
<tr>
<TD width= "11%" >
<div align= "right" Annex 2: </div>
</td>
<TD width= "89%" >
<input type= "File" Name= "File_up1" size= "50"
</td>
</tr>
<tr>
<TD width= "11%" >
<div align= "right" Annex 3: </div>
</td>
<TD width= "89%" >
<input type= "File" Name= "file_up2" size= "50"
<input type=hidden name= "Fileuploadend"
</td>
</tr>
<tr>
<TD width= "11%" >
<div align= "right" > </div>
</td>
<TD width= "89%" >
<input Type=submit value= Determination
</td>
</tr>
</table>
</Form>
</body>
But this is only to get the sender's IP address and MAC address, but also prohibit users to change their own IP address code, because our system is the need for personal modification of the IP behavior to prohibit.
<%
StrIP = Request.ServerVariables ("REMOTE_ADDR")
Set net = Server.CreateObject ("Wscript.Network")
Set sh = Server.CreateObject ("Wscript.Shell")
Sh.run "%comspec%/C Nbtstat-a" & StrIP & "> C:\" & strip & "TXT", 0,true
Set sh = Nothing
Set fso = CreateObject ("Scripting.FileSystemObject")
Set ts = fso.opentextfile ("C:\" & StrIP & ". txt")
MACAddress = null
Do and not TS. AtEndOfStream
data = UCase (Trim (ts.readline))
If InStr (Data, "MAC address") Then
MACAddress = Trim (Split (data, "=") (1))
Exit do
End If
Loop
Ts.close
Set ts = Nothing
Fso.deletefile "C:\" & StrIP & ". txt"
Set FSO = Nothing
Getmacaddress = MACAddress
Strmac = getmacaddress
Set Conn=server. CreateObject ("Adodb.connection")
Conn.Open "dsn=; uid=; Pwd= "
Dsnpath= "dsn=; uid=; Pwd= "
Set Rs=server. CreateObject ("Adodb.recordset")
Sele= "SELECT * from Getmac where g_mac= '" &strMac& ""
Rs.Open Sele,dsnpath
If Rs.bof Then
Set Conn=server. CreateObject ("Adodb.connection")
Conn.Open "dsn=; uid=; Pwd= "
Dsnpath= "dsn=; uid=; Pwd= "
Set Rs=server. CreateObject ("Adodb.recordset")
G_id=mid (strip,9)
G_id=left (g_id,2)
' Response.Write g_id
If IsNumeric (g_id) Then
G_id=cint (g_id)
Else
G_id=0
End If
sele= INSERT INTO Getmac (G_IP,G_MAC,G_ID,G_OK) VALUES (' &strIP& ', ' &strMac& ', ' &g_id& ', 0 )"
Rs.Open Sele,dsnpath
Else
Set Conn=server. CreateObject ("Adodb.connection")
Conn.Open "dsn=; uid=; Pwd= "
Dsnpath= "dsn=; uid=; Pwd= "
Set Rs=server. CreateObject ("Adodb.recordset")
Sele= "SELECT * from Getmac where g_ip= '" &trim (StrIP) & "' and G_mac= '" &trim (STRMAC) & ""
Rs.Open Sele,dsnpath
If Rs.bof or rs.eof then
Set Rs1=server. CreateObject ("Adodb.recordset")
sele= "INSERT into Badmac (IP, Mac, Thetime) VALUES (' &strIP&" ', ' "&strMac&" ', ' "&now () &") "
Rs1.open Sele,dsnpath
Response.Redirect ("/reg/wrong.asp")
Response.End
End If
End If
%>
<link rel= "stylesheet" type= "Text/css" href= "/css/forum". CSS ">
<style type=text/css>
!--
input {font-size:9pt; color: #0011dd; Background-color: #e9e9f9; padding-top:0px}
Select {font-size:9pt; color: #0011dd; Background-color: #e9e9f9; padding-top:0px}
textarea {font-size:9pt; color: #0011dd; Background-color: #e9e9f9; padding-top:0px}
-->
</style>
<title> mail system </title> <%
Response.expires=0
Function Bin2str (BINSTR)
Dim Varlen,clow,ccc,skipflag
Skipflag=0
CCC = ""
If not IsNull (BINSTR) Then
Varlen=lenb (BINSTR)
For I=1 to Varlen
If skipflag=0 Then
Clow = MidB (binstr,i,1)
If AscB (Clow) > 127 Then
CCC =CCC & Chr (AscW (MidB (binstr,i+1,1) & Clow))
Skipflag=1
Else
CCC = CCC & Chr (AscB (Clow))
End If
Else
Skipflag=0
End If
Next
End If
BIN2STR = CCC
End Function
Varbytecount = Request.TotalBytes
' Response.Write Varbytecount
Bncrlf = ChrB (+) & ChrB (10)
Binhttpheader=request.binaryread (Varbytecount)
' Response.Write Vbenter
' Response.Write '
"& CStr (Binhttpheader) &"
"
Sread=0
Eread=0
' Start reading data from non-file fields
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "dsn=; uid=; Pwd= "
Sql= "SELECT * from T_mail where mailid=0"
Set Rs=server. CreateObject ("ADODB.") Recordset ")
Rs. Open sql,conn,3,3
Rs.addnew
RS ("EmailLevel") =0
RS ("Receempl") = ""
Do While LenB (Binhttpheader) >46
Divider = LEFTb (Binhttpheader, INSTRB (Binhttpheader, Bncrlf)-1)
Binheaderdata = Leftb (Binhttpheader, INSTRB (Binhttpheader, Bncrlf & Bncrlf)-1)
Strheaderdata=bin2str (Binheaderdata)
Lngfieldnamestart=instr (Strheaderdata, "name=" &CHR) +len ("Name=" &CHR (34))
' Response.Write '
Lngfieldnamestart: "&lngfieldnamestart
Lngfieldnameend=instr (LNGFIELDNAMESTART,STRHEADERDATA,CHR (34))
' Response.Write '
Lngfieldnameend: "&lngfieldnameend
Strfieldname=mid (Strheaderdata,lngfieldnamestart,lngfieldnameend-lngfieldnamestart)
' Response.Write ' <BR> strfieldname: ' & strFieldName
Strfieldname=trim (strFieldName)
Strfieldname=replace (strfieldname,vbcrlf,vbnullstring)
' When you start to judge the file data
If StrComp (strFieldName, "Fileuploadstart", 1) =0 and Sread=0 Then
"Response.Write" found where the file started.
Sread=1
' Response.Write '
"& INSTRB (Datastart + 1, Binhttpheader, divider) &"
"
Binhttpheader=midb (BINHTTPHEADER,INSTRB (Datastart + 1, Binhttpheader, divider))
Exit Do
End If
Datastart = INSTRB (Binhttpheader, Bncrlf & Bncrlf) + 4
Dataend = INSTRB (Datastart + 1, Binhttpheader, divider)-Datastart
Binfieldvalue=midb (Binhttpheader, Datastart, Dataend)
Strfieldvalue=bin2str (Binfieldvalue)
' Strfieldvalue=trim (Strfieldvalue)
Strfieldvalue=replace (Strfieldvalue, "", "")
' Non-File Upload field variable assignment
' Execute strfieldname& ' = ' ' &strFieldValue& ' '
' Response.Write strfieldname& ': "&strFieldValue&"
"
If Strfieldname= "Geterempl" Then
Strfieldvalue=replace (strfieldvalue,vbcrlf,vbnullstring)
If InStr (Strfieldvalue, "GR:") =1 Then
' Mail Group Hair
' Response.Write Len (Trim (strfieldvalue))
If Len (Trim (strfieldvalue)) <> 6 Then
' Format error returned
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The collection group you entered is malformed!") \ r The correct format is: ' gr:001 ' ");
History.back ();
</script>
<p>
<%
Response.End
Else
If not IsNumeric (mid trim (Strfieldvalue), 4) Then
' Format error returned
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The collection group you entered is malformed!") \ r The correct format is: ' gr:001 ' ");
History.back ();
</script>
<p>
<%
Response.End
Else
Thegroup= (Mid (Trim (Strfieldvalue), 4))
End If
End If
Tmpsql= "SELECT * from T_group where owner= '" &session ("myID") & "' and Groupidowner= '" &thegroup& ""
' Response.Write Tmpsql
Set Tmprs=server. CreateObject ("ADODB.") Recordset ")
Tmprs. Open Tmpsql,conn
If Tmprs.bof or tmprs.eof then
' The group was not found
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The collection group you entered <%=thegroup%> was not found!") ");
History.back ();
</script>
<p>
<%
Response.End
Else
If Tmprs ("Personnum") =0 Then
' No users in group
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("You have entered a collection group <%=thegroup%> that currently does not have any users \ nthe cannot send");
History.back ();
</script>
<p>
<%
Response.End
Else
Strfieldvalue=trim (Tmprs ("Groupempl"))
Tmprs.close
Set tmprs=nothing
End If
End If
End If
If InStr (Strfieldvalue, "|") Then
' Group Hair
Allsearch=replace (Trim (strfieldvalue), "|", "', '")
Allsearch= "'" &allsearch& ""
Tmpstring=trim (strfieldvalue) & "|"
Tosearch= ""
Do While Len (tmpstring) >=5
Tosearch=left (tmpstring,5)
Tmpstring=mid (tmpstring,7)
If InStr (Tosearch, "|") Then
' Bad format
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The recipient you entered is malformed!");
History.back ();
</script>
<p>
<%
Response.End
End If
Tmpsql= "SELECT * from" (select UserID to T_officer where UserID in ("&allsearch&")) Derivedtbl where userid= ' "&am p;tosearch& "'"
' Response.Write Tmpsql
Set Tmprs=server. CreateObject ("ADODB.") Recordset ")
Tmprs. Open Tmpsql,conn
If tmprs.eof or Tmprs.bof then
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The recipient you entered is <%=tosearch%> not found!");
History.back ();
</script>
<p>
<%
Response.End
End If
Tmprs.close
Set tmprs=nothing
Loop
Strfieldvalue=trim (Strfieldvalue)
Else
If Len (Trim (strfieldvalue)) <> 5 Then
' Not properly formatted
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The recipient you entered <%=trim (strfieldvalue)%> incorrect!");
History.back ();
</script>
<p>
<%
Response.End
Else
If IsNumeric (the trim (strfieldvalue)) Then
Tmpsql= "SELECT * from T_officer where userid= '" &trim (strfieldvalue) & ""
Set Tmprs=server. CreateObject ("ADODB.") Recordset ")
Tmprs. Open Tmpsql,conn
If tmprs.eof or Tmprs.bof then
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The recipient you entered <%=trim (Strfieldvalue)%> did not find \ r The employee may not have been registered!");
History.back ();
</script>
<p>
<%
Response.End
End If
Tmprs.close
Set tmprs=nothing
Strfieldvalue=trim (Strfieldvalue)
Else
%>
Attempt to send a message, but failed, please modify the error and try again!
<script language= "JavaScript" >
Alert ("The recipient you entered <%=trim (strfieldvalue)%> incorrect!");
History.back ();
</script>
<p> <%
Response.End
End If
End If
End If
End If
Strfieldvalue=replace (Strfieldvalue, "", "") "
' Response.Write strFieldName
RS (strfieldname) =replace (Strfieldvalue, ">", ">")
Binhttpheader=midb (BINHTTPHEADER,INSTRB (Datastart + 1, Binhttpheader, divider))
Loop
' Start working with file data
Titem=0
RS ("Filesize_1") =0
RS ("filesize_2") =0
RS ("Filesize_3") =0
Do While LenB (Binhttpheader) >46
If INSTRB (Binhttpheader, Bncrlf & Bncrlf) <> 0 Then
Binheaderdata = LeftB (BINHTTPHEADER,INSTRB (Binhttpheader, Bncrlf & Bncrlf)-1)
Else
Exit Do
End If
Strheaderdata=bin2str (Binheaderdata)
' Read Content-type of uploaded files
Lngfilecontenttypestart=instr (Strheaderdata, "Content-type:") +len ("Content-type:")
Strfilecontenttype=trim (Mid (Strheaderdata,lngfilecontenttypestart))
Strfilecontenttype=replace (strfilecontenttype,vbcrlf,vbnullstring)
' Read the uploaded file name
If InStr (Strheaderdata, "filename=") >0 Then
Lngfilenamestart=instr (Strheaderdata, "filename=" &CHR) +len ("Filename=" &CHR (34))
Lngfilenameend=instr (LNGFILENAMESTART,STRHEADERDATA,CHR (34))
Strfilename=mid (Strheaderdata,lngfilenamestart,lngfilenameend-lngfilenamestart)
Strfilename=trim (strFileName)
Strfilename=replace (strfilename,vbcrlf,vbnullstring)
Else
Strfilename= ""
End If
' Read uploaded file data
Datastart = INSTRB (Binhttpheader, Bncrlf & Bncrlf) + 4
Dataend = INSTRB (Datastart + 1, Binhttpheader, divider)-Datastart
If strfilename <> "" Then
If Dataend>0 Then
Binfieldvalue=midb (Binhttpheader, Datastart, Dataend)
' Write uploaded files to the database
Titem=titem+1
' Response.Write ' TItem: "&titem
RS ("Filecontenttype_" &titem) =strfilecontenttype
RS ("Filecontent_" &titem). AppendChunk Binfieldvalue
RS ("Filesize_" &titem) =lenb (Binfieldvalue)
RS ("Filename_" &titem) =strfilename
Else
Binfieldvalue=binhttpheader
End If
End If
If INSTRB (Datastart + 1, binhttpheader, divider) >0 Then
Binhttpheader=midb (BINHTTPHEADER,INSTRB (Datastart + 1, Binhttpheader, divider))
Else
Binhttpheader= ""
End If
Loop
RS ("Sizetotal") =csng (RS ("Filesize_1")) +csng (RS ("filesize_2")) +csng (RS ("Filesize_3")) +csng (Len (RS ("body")) + CSng (Len ("Emailtitle")) +csng (Len ("Emailshowname")) +csng (Len ("Geterempl"))
If CSng (RS ("Sizetotal")) >=csng (2*1024*1024) Then
Response.Write "Sorry, the file is too large, please ensure that the total size of each message does not exceed 2m!"
Response.End
End If
RS ("Mailtime") =now
RS ("Readerempl") = ""
If RS ("Receempl") <> "then"
RS ("Receempl") =session ("myID")
RS ("Readerempl") =session ("myID")
End If
RS ("Deleempl") = ""
RS ("Deleverempl") = ""
RS ("Sendmac") =strmac
Rs.update
Rs.close
Set rs=nothing
Conn. Close
Set conn=nothing
%>
<script language=javascript>
window.open ("mailok.asp", target= "_self")
</script>
</body>
Finally, let's talk about how to read the content out of the database, there are several categories of content, such as the browser can display, such as *.htm, a category is required to download, such as *.exe, there is a browser can be displayed but not allowed to display, such as *.asp, see the code:
<%
response.buffer= true
Response.Clear
function GetName (oriname)
Thename=oriname
Do While InStr (Thename, "/") >0
Thename=mid (Thename,instr (thename, "/") +1)
Loop
Do While InStr (Thename, "\") >0
Thename=mid (Thename,instr (thename, "\") +1)
Loop
Getname=thename
End Function
function Canexec (Thechar)
If InStr (Thechar, ". asp") >0 Then
Canexec=false
Exit function
End If
If InStr (Thechar, ". Asa") >0 Then
Canexec=false
Exit function
End If
If InStr (Thechar, ". aspx") >0 Then
Canexec=false
Exit function
End If
If InStr (Thechar, ". asax") >0 Then
Canexec=false
Exit function
End If
Canexec=true
End Function
Mailid=request ("Mailid")
Se=request ("se")
If SE <> 1 and se <> 2 and SE <> 3 Then
Response.End
End If
Set conn=server.createobject ("Adodb.connection")
Set Rs=server.createobject ("Adodb.recordset")
Conn.Open "dsn=; uid=; Pwd= "
Sql= "SELECT * from T_mail where (Geterempl like '%" &session ("myID") & "%" or deleempl like '% "&session (" myID ") & "%" or receempl like '% "&session (" myID ") &"% ") and (not deleverempl like '% ' &session (" myID ") &"% ") nd mailid= ' "&mailid&" "
Rs.Open sql,conn,3,3
If rs.eof or Rs.bof then
Response.End
End If
If RS ("Filecontenttype_" &trim (SE)) <> "Text/plain" or (Not Canexec (GetName (Trim (RS ("filename_" &trim (SE)))) Then
Response.ContentType = RS ("filecontenttype_" &trim (SE))
End If
' Response.AddHeader ' content-type ', ' application/x-msdownload '
If InStr (Response.ContentType, "Application") >0 Then
Response. AddHeader "Content-disposition", "attachment;filename=" &getname (Trim (RS ("filename_" &trim (SE)))
End If
Response.BinaryWrite rs ("Filecontent_" &trim (SE))
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
Article to the end of this, as for the data structure of the mail database everyone based on their own thinking of the code it!